/*****Natur Product*****/
var W3CDOM = (document.createElement && document.getElementsByTagName);
var cur_sel = 1;

if ( window.addEventListener ) {
	window.addEventListener('load', init, false);
}else {
	window.attachEvent('onload', init, false);
}
function init () {
	if (!W3CDOM) return;
	if ( document.getElementById('filtr1') ) {
		document.onclick = whichElement;
		cur_sel = 1;
		pseudoSelect();
		cur_sel = 2;
		pseudoSelect();
		cur_sel = 0;
	}
}
var ie = false;

opera = (window.opera) ? true : false;
ie = (document.all && !opera) ? true : false;

var version = 6;
var flash = false;
if (navigator.plugins) {
	if (navigator.plugins["Shockwave Flash"]) {
		plugin = navigator.plugins["Shockwave Flash"].description;
		  if ( parseInt(plugin.charAt(plugin.indexOf('.') - 2))) {
            flash = parseInt(plugin.charAt(plugin.indexOf('.') - 2) * 10) >= version;
        }
        else {
            flash = parseInt(plugin.charAt(plugin.indexOf('.') - 1)) >= version;
        }
	} else {
		if ((navigator.userAgent.indexOf('MSIE') != -1)&&(navigator.userAgent.indexOf('Win') != -1)) {
			var vb = '<script language="vbscript">\n'
			+ ' on error resume next\n'
			+ ' flash = IsObject(CreateObject('
			+ ' "ShockwaveFlash.ShockwaveFlash.' + version + '"))\n'
			+ '<' + '/script>';
			document.write(vb);
		}
	}
}

var 	tname ;

var feedback_flag = 0;

function whichElement(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) { // defeat Safari bug
		targ = targ.parentNode;
	}

	tname = targ.tagName;
	if(document.getElementById('filtr1')) {
		if ( tname != 'SPAN' ) {
//			select_list.style.display = 'none' ;
			document.getElementById('sel_ul_1').style.visibility = 'hidden';
			document.getElementById('sel_ul_2').style.visibility = 'hidden';
			cur_sel = 0;
		}
	}
}


function pseudoSelect() {
	var aim_form = document.getElementById('filtr1');
	if (aim_form == null) {
	    return;
	}
	var pseudo_selct = document.getElementById('sel' + cur_sel);
	if (pseudo_selct == null) {
	    return;
	}


	var default_select = aim_form.getElementsByTagName('select');

	for (var i = 0 ; i < default_select.length ; i++ ) {
		default_select[i].style.display = 'none';
	}
	var but = aim_form.getElementsByTagName('BUTTON')[0];
	if (but.className != "forward")
		but.style.display = 'none';

	select_list = pseudo_selct.getElementsByTagName('UL')[0];

	arr = pseudo_selct.getElementsByTagName('SPAN')[0];
	arr.style.display = 'block';
	switch (cur_sel) {
	    case 1:
	       arr.onclick = open_select_list1;
	       break;
	    case 2:
	       arr.onclick = open_select_list2;
	       break;
	}

	var list_item = select_list.getElementsByTagName('LI');

	for ( var j = 0 ; j < list_item.length ; j++ ) {
		list_item[j].onclick = get_value;
		list_item[j].onmouseover = hover_style ;
		list_item[j].onmouseout = out_style ;
	}
}

function FilterBtnSub() {
    cur_sel = 0;
    //return get_value();
}

function open_select_list1() {
/* old 24.11.2009
	var el = document.getElementById("sel_ul_1");
	el.style.display = ( el.style.display == 'block' ) ? 'none' : 'block' ;
	cur_sel = 1;
*/
	switch( cur_sel ){
	case 1:
		document.getElementById('sel_ul_1').style.visibility = 'hidden';
		cur_sel = 0;
		break;
	default:
		document.getElementById('sel_ul_1').style.visibility = 'visible';
		document.getElementById('sel_ul_2').style.visibility = 'hidden';
		cur_sel = 1;
		break;
	}
}

function open_select_list2() {
/* old 24.11.2009
	var el = document.getElementById("sel_ul_2");
	el.style.display = ( el.style.display == 'block' ) ? 'none' : 'block' ;
	cur_sel = 2;
*/
	switch( cur_sel ){
	case 2:
		//el.style.display = ( el.style.display == 'block' ) ? 'none' : 'block' ;
		document.getElementById('sel_ul_2').style.visibility = 'hidden';
		cur_sel = 0;
		break;
	default:
		document.getElementById('sel_ul_1').style.visibility = 'hidden';
		document.getElementById('sel_ul_2').style.visibility = 'visible';
		cur_sel = 2;
		break;
	}
}

function close_item() {
	this.style.display = 'none';
}

function DetectSearchData() {
    var srch_txt = document.getElementById('i89').value;
	    if (!srch_txt.length) {
	        alert(document.getElementById('srch_txt_message').value);
        return false;
	    } else if (srch_txt.length < 3) {
	        alert(document.getElementById('srch_too_small').value);
        return false;
	    }
	return true;
}

function get_value() {
   	 if (cur_sel > 0) {
        select_list.style.display = 'none';
   	    var str = this.id + '';
   	    var i;
        str = str.substr(3);
        var def_sel = document.getElementById('default_select' + cur_sel);
        def_sel.selectedIndex = parseInt(str) + 1;
        if (!feedback_flag) {
            document.location.href = def_sel.value;
        } else {
            for (i = 0; i < def_sel.options.length; i++) {
                if (def_sel.options[i].value == this.id) {
                    def_sel.selectedIndex = i;
                    document.getElementById('select_window2').innerHTML = def_sel.options[i].text;
                    break;
                }
            }
        }
        return false;
   	}
}

function hover_style() {
	this.className += ' ie6over';
}

function out_style() {
	this.className = this.className.replace(new RegExp(" ie6over\\b"), "");
}
/*************** standart *******************/

function ShowPhoto(url, width, height) {
	var scroll = (screen.width < 1000) ? "yes" : "no";
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	window.open(url, '_blank', param+'menubar=no,scrollbars=' + scroll + ',status=no');
}
//--------------------------------// Print Flash
function PrintFlash(path, wid, heg, pic, lnk, paramz) {
    if(flash && path){
		document.open();
		document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="6,0,0,0" width="' + wid + '" height="' + heg + '">');
		document.write ('<param name=movie value="' + path + '"/>');
		document.write ('<param name="quality" value="high"/>');
		document.write ('<param name="menu" value="false"/>');
		document.write ('<param name="wmode" value="opaque"/>');
		document.write ('<param name="FlashVars" value="' + paramz + '"/>');
		document.write ('<embed wmode="opaque" src="' + path + '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + wid + '" height="' + heg +'" FlashVars="' + paramz + '" menu="false"></embed>');
		document.write ('</object>');
		document.close();
	} else {
		document.open();
		if(lnk != '') document.write ('<a href="'+ lnk +'">');
		document.write('<img src="'+ pic +'"/>')
		if(lnk != '') document.write ('</a>');
		document.close();
	}
}
//---- width="'+ wid +'" height="'+ heg +'"---//
//--------------------------------// Get Splitted Link
function GetLink (splited_link, target) {
	newlink = unescape(splited_link).replace(/\|/g, '');

	if (target == 1 && newlink.substr(0, 6) != 'mailto') {
		newwin = window.open(newlink, '_blank', 'toolbar=1,scrollbars=1,status=1,location=1,menubar=1,resizable=1,personalbar=1');
		if (newwin) {
			newwin.focus();
		}
	} else {
		window.location = newlink;
	}
}

var menu_elements_count = 5;

startList = function() {
		var nodes = document.getElementById("main_nav").getElementsByTagName('UL')[0].getElementsByTagName("LI");
		var nobj, nobj_li;
		var off_y = 0;
		var vtop;
		var node_ind = -1;
		var i;

		menu_elements_count = 0;
		for (i=0; i<nodes.length; i++) {
              if (nodes[i].className == "li_first") {
		          menu_elements_count = menu_elements_count + 1;
              }
		}

        for (i=0; i<nodes.length; i++) {
                nobj = nodes[i].getElementsByTagName('UL')[0];

              if (nodes[i].className == "li_first") {
		          node_ind = node_ind + 1;
              }

		    if (nobj != undefined) {
		      nobj_li = nobj.getElementsByTagName("LI");


		      vtop = Math.round(nobj_li.length / 2);

		      if (vtop > i + 1) {
		          vtop = i + 1;
		      }

		      while (nobj_li.length + vtop + node_ind - 1 > menu_elements_count) {
		          vtop = vtop - 1;
		      }

		      off_y = (vtop - 1 + node_ind) * 40;
		      if ((nobj_li.length & 1) == 0 && node_ind != 0 && node_ind != menu_elements_count - 1) {
		          off_y = off_y - 20;
		      }
		      off_y = off_y - 80;
		      if (off_y < 0) {
		          off_y = 0;
		      }

		      nobj.style.top = off_y + 'px';

		    }
		        nodes[i].onmouseover = function() {
				this.className += " lihover";
			}
				nodes[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp("lihover\\b"), "");
			}
		}
}
window.onload = initt;
function ie_hover() {
	var nodes = document.getElementsByTagName('TD');
	for ( var j = 0 ; j < nodes.length ; j++ ) {
		if ( nodes[j].className.match('item') ) {
			nodes[j].onmouseover = function() {
				this.className += " tdhover";
			}
				nodes[j].onmouseout = function() {
				this.className = this.className.replace(new RegExp("tdhover\\b"), "");
			}
		}
	}
}
function initt() {
    startList();
	ie_hover();
}

//--------------------------------// Slide
function Slide (id) {
	if (!(objb = document.getElementById(id+'_block')) || !(objl = document.getElementById(id+'_link'))) {
		return;
	}

	if (!objb.style.display || objb.style.display == 'none') {
		objb.style.display = 'block';
		objl.className = 'slideopen';
	} else {
		objb.style.display = 'none';
		objl.className = 'slideclose';
	}
}
/*****set default search_form value*****/

function set_form_value(){
	var form_val=document.getElementById('search_inp');
	//document.getElementById('what_ask').style.display = 'none';
	val = form_val.value;
	form_val.onfocus = get_from_val;
	form_val.onblur = blur_val;
}
function get_from_val(){
		this.value='';
	}
function blur_val(){
		if(this.value=='' || !this.value){
			this.value = val;
		}
	}
/*
if (window.attachEvent) {
	window.attachEvent('onload', set_form_value);
} else if (window.addEventListener) {
	window.addEventListener('load', set_form_value, false);
}*/

var current_new = 0;
var current_first = 0;

/***** use on main page *****/

function getNextData(obj) {
    var sId = obj.id;
    var part = parseInt(sId.substr(10));

    var inc = 1;
    if (sId.substr(5, 4) == 'prev') {
        inc = -1;
    }

    var count = parseInt(document.getElementById('count_' + part).value);
    if (part == 1) {
        current_new = current_new + inc;
    }
    var cur = current_new;
    if (part == 2) {
        current_first = current_first + inc;
        cur = current_first;
    }
    var tRow = document.getElementById('part_' + part).tBodies[0].rows[0];
    var div1 = tRow.cells[0].getElementsByTagName('div')[0];
    div1.innerHTML = document.getElementById('div_' + part + '_item_' + cur).innerHTML;
    var div2 = tRow.cells[1].getElementsByTagName('div')[0];
    div2.innerHTML = document.getElementById('div_' + part + '_item_' + (cur + 1)).innerHTML;
    var max = div1.offsetHeight;
    if (div2.offsetHeight > div1.offsetHeight) {
        max = div2.offsetHeight;
    }
    max = max + 55;
    document.getElementById('new_top_div_' + part).style.height = max + 'px';
    if (cur > 0) {
        document.getElementById('href_prev_' + part).style.display = 'block';
    } else {
        document.getElementById('href_prev_' + part).style.display = 'none';
    }

    if (cur + 2 < count) {
        document.getElementById('href_next_' + part).style.display = 'block';
    } else {
        document.getElementById('href_next_' + part).style.display = 'none';
    }

}

init();


var TJS = {};


(function(){
	TJS.$ = function (id) {return document.getElementById(id)};
	TJS.show = function (com,x,y) {
		var c = TJS.$('flWin');
		var l = TJS.$('flLink');
		l.href = com.link;
		l.innerHTML = com.name;
		c.className ='aaa';
		c.style.top = y + 10 +  'px';
		c.style.left = x + 10 + 'px';
		c.onmouseout = function () {
			this.className = '';
		}
		c.onmouseover = function () {
			this.className='aaa';
		}
		var c =  TJS.$('flCity');
		c.innerHTML = com.city;
		if (com.city == "") c.style.display='none';
		else c.style.display='block';
		var m =  TJS.$('flMail');
		m.href='mailto:' + com.mail;
		m.innerHTML = com.mail;
		if (com.mail == "") m.style.display='none';
		else m.style.display='block';
	}
}());


function flashMapMenu (id ,x , y) {
	var com = false;
	if (COMPANY) {
		for (i in COMPANY) {
			if (COMPANY[i].id == id) {
				com = COMPANY[i];
			}
		}
	} 
	if (com) {
		TJS.show(com, x, y);
	}	
}


$(document.body).ready (function(){
     $('.pseudo_selct').each(function(){
             $('.clicker', $(this)).click(function () {
                   MyPseudoSelect(this); 
             })
         });
 });


function MyPseudoSelect(obj) {
     var p = $(obj).parent();
     var ul = $('ul', p).show();
     ul.css('z-index', 10001);
     p.parent().css('z-index', 10001);
     $('li', ul).each(function(){
            $(this).click(function(){
                $(obj).html($(this).html());
                var val = $(this).attr('id');
                $('option',p).each(function(){
                        if ($(this).val() == val) {
                            $(this).attr('selected',true);
                        }
                    });
                ul.hide();
                ul.css('z-index',10000);
                p.parent().css('z-index', 1000);
            });
     });
}

function _goto (obj, id) {
    if ($(obj).attr('type') == 'radio') {
        $('input[name="' + $(obj).attr('name')  + '"]', $('.auto_form')).each (function(){
                if ($(obj).attr('id') != $(this).attr('id')) {
                    $(this).click(function(){
                             $('#f' + id).hide();
                        });
                }
            });
    }
    if (obj.checked) {
        if ($('#f' + id) && $('#f' + id).attr('rel') == 'hide') {
            $('#f' + id).show();
        }
        else {
            document.location = document.location.href.replace('#f' + id, '') + '#f' + id;
        }
    }
    else {
        if ($('#f' + id) && $('#f' + id).attr('rel')=='hide') {
            $('#f' + id).hide();
        }
    }
}
