var winW, winH;

jQuery(function()
{
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 else if (navigator.appName.indexOf("Microsoft")!=-1) {
  if (document.body) {
      winW = document.body.offsetWidth;
  } else {
      winW = window.innerWidth;
  }
  if (document.documentElement) {
      winH = document.documentElement.clientHeight;
  } else {
      winH = window.innerHeight;
  }
 }
 // lets set it to all other brosers as well
 else{
     winW = window.innerWidth;
     winH = window.innerHeight;
 }
}
});



function submit_search_compl(input_id,kw) {
//	var s_in = document.getElementById(input_id).value;

    var search_url = '/search.php?popup=1&complsearch=1&kw='+encodeURI(kw)+'&pid='+input_id;
	//var search_url = '/search.php?popup=1&pid='+input_id+'&kw=truck';
	document.getElementById('spop').style.width='650px';
	document.getElementById('t_win1').style.width='650px';
	document.getElementById('popup_content').style.height='350px';
	document.getElementById('spop').style.left=Math.round((winW / 2) - (650/2))+'px';
	//document.getElementById('spop').style.top=Math.round((winH / 2) - (300/2))+'px';
	document.getElementById('spop').style.top="120px";

    	document.getElementById('popup_title').innerHTML=tg('General search');
	document.getElementById('spop').style.visibility='visible';
	xmlreq_put(search_url,'popup_content','sorttable.init()');

}



function submit_search(input_id) {
	var s_in = document.getElementById(input_id).value;
        var search_url = '/search_general.php?popup=1&kw='+encodeURI(s_in);

	document.getElementById('spop').style.width='650px';
	document.getElementById('t_win1').style.width='650px';
	document.getElementById('popup_content').style.height='300px';
	document.getElementById('spop').style.left=Math.round((winW / 2) - (650/2))+'px';
	//document.getElementById('spop').style.top=Math.round((winH / 2) - (300/2))+'px';
	document.getElementById('spop').style.top="120px";

    	document.getElementById('popup_title').innerHTML=tg('General search');
	document.getElementById('spop').style.visibility='visible';
	xmlreq_put(search_url,'popup_content','sorttable.init()');

}

function open_search () {
	var tab_num = 0;
	if (arguments.length){
		var tab_num = arguments[0];
	}
	//_css(d('popup_content'),{'overflow':'auto'});
	var hs_xtr = document.getElementById('hs_xtra_notype');
	var hs_xtra = '?';
	if (hs_xtr) {
		hs_xtra = hs_xtr.value;
	}
	var p_tbl = dd.call(d('spop'),'table')[0];
	var p_cell = dd.call(p_tbl,'td')[0];
	var popup_width = 800;
	var popup_height = 430;
    var search_url = '/search.php'+hs_xtra+'&popup=1';
//alert(search_url);
	document.getElementById('spop').style.left=Math.round((winW / 2) - (popup_width/2))+'px';
	document.getElementById('t_win1').style.width=popup_width+'px';
	document.getElementById('spop').style.width=popup_width+'px';
	p_tbl.width = popup_width;
	p_tbl.style.width = p_tbl.width+'px';
	p_cell.width = p_tbl.width-20;
	document.getElementById('popup_content').style.height=popup_height+'px';
    document.getElementById('popup_title').innerHTML=tg('Advanced Search');
	document.getElementById('spop').style.visibility='visible';
	xmlreq_load(search_url,'popup_content',function(){
		var r_tbl = dd.call(this,'table')[0];
		r_tbl.width = p_cell.width-20;//'100%';
		_css(r_tbl,{'margin-left':'20px'});
		_css(d('chemical_selector'),{width:'100%'});
		set_evt(d('wp'),'keyup',format_numeric_input);
		if (tab_num){
			var tab = d('mt_T'+tab_num);
			if (tab.onclick) tab.onclick();
		}
	});
}

function submit_advanced_search_with_sort() {
	var s1 = document.getElementById('s1');
	var s1o = document.getElementById('s1o');
	var s2 = document.getElementById('s2');
	var s2o = document.getElementById('s2o');
	var s3 = document.getElementById('s3');
	var s3o = document.getElementById('s3o');
	var hs_xtra = document.getElementById('hs_xtra').value;

	var s1v = s1.options[s1.selectedIndex].value;
	var s2v = s2.options[s2.selectedIndex].value;
	var s3v = s3.options[s3.selectedIndex].value;
	var s1ov = s1o.options[s1o.selectedIndex].value;
	var s2ov = s2o.options[s2o.selectedIndex].value;
	var s3ov = s2o.options[s3o.selectedIndex].value;


	var geturl = '/search.php'+hs_xtra+'&s1='+s1v+'&s2='+s2v+'&s3='+s3v+'&s1o='+s1ov+'&s2o='+s2ov+'&s3o='+s3ov;

	xmlreq_put(geturl,'popup_content','sorttable.init()');
}

function submit_advanced_search() {
        var insz = '';
	var ob = document.getElementById('hose_search_size');
	for (var i=0; i < ob.options.length; i++) {
		if (ob.options[i].selected) {
		insz = ob.options[i].value;
		}
	}
	if (insz == '') {
		alert(tg('Please select hose size!'));
		return (false);
	}
        var instr = '';
	var ob = document.getElementById('chemical_selector');
	for (var i=0; i < ob.options.length; i++) {
		if (ob.options[i].selected) {
		instr = instr + ob.options[i].value + '##';
		}
	}
        var wp_val = document.getElementById('wp').value;
//        var bp_val = document.getElementById('bp').value;
        var tmin_val = document.getElementById('tmin').value;
        var tmax_val = document.getElementById('tmax').value;
//        var fs = document.getElementById('fs');
//		var fs_val = fs.options[fs.selectedIndex].value;
        var cu = document.getElementById('cu');
		var cu_val = cu.options[cu.selectedIndex].value;

	document.getElementById('spop').style.left=Math.round((winW / 2) - 400)+'px';
	document.getElementById('spop').style.width='770px';
	document.getElementById('t_win1').style.width='770px';
	document.getElementById('popup_content').style.height='400px';
	document.getElementById('popup_title').innerHTML=tg('Advanced Search - Results');
	document.getElementById('spop').style.visibility='visible';

//	var geturl = '/search.php?type=hosesearch&wp='+wp_val+'&bp='+bp_val+'&tmin='+tmin_val+'&tmax='+tmax_val+
//	var geturl = '/search.php?type=hosesearch&wp='+wp_val+'&tmin='+tmin_val+'&tmax='+tmax_val+                     '&hosesize='+escape(insz)+'&fs='+fs_val+'&chemsearch='+escape(instr);
	var geturl = '/search.php?type=hosesearch&wp='+wp_val+'&tmin='+tmin_val+'&tmax='+tmax_val+
                     '&hosesize='+escape(insz)+'&cu='+cu_val+'&chemsearch='+escape(instr);

	xmlreq_put(geturl,'popup_content','sorttable.init()');

}

function open_hose(productid){
         window.open('/technical.php?s=1&pid='+productid, 'signaturetech',
           'width=700,height=530,left='+(screen.width / 2 - 350)+ ',top='+(screen.height / 2 - ".(530/2).")+',location=no,menubar=no,toolbar=no,scrollbars=1');
}
function open_overview(productid){
         window.open('/cat.php?p='+productid);
}
function flange_search() {
	var s1 = d('sel1');
	var s2 = d('sel2');
	//var s3 = d('sel3');
	var s4 = d('sel4');

	//alert();

	var get_url = '/search.php?flangesearch='+s1.options[s1.selectedIndex].value + ',' + s2.options[s2.selectedIndex].value +','+ /*s3.options[s3.selectedIndex].value+','+*/ s4.options[s4.selectedIndex].value;

	xmlreq_put(get_url,'flange_search_results','sorttable.init()');
}

function nz_search(){
	var nozzle_form = d('nozzle_search_form');
	var conditions = dd.call(nozzle_form,'select');
	var search_params = {};
	for (var i=0;i<conditions.length;i++){
		search_params[conditions[i].id] = conditions[i].options[conditions[i].selectedIndex].value;
	}
	var post_data = _map_get_args(search_params).trim('?');
	d('nz_search_results').className += ' loading';
	d('nz_search_results').innerHTML = 'Loading...';
	do_ajax('/search.php?nozzlesearch=1',post_data,nz_search_results);
	//clog(search_params);
	return false;
}

function nz_search_results(response){
	var result_block = d('nz_search_results');
	result_block.className = (' '+result_block.className+' ').replace(' loading ','');
	//clog(response);
	result_block.innerHTML = response;
	sorttable.init();
}

function ej_search(){
	var ej_form = d('ej_search_form');
	var conditions = dd.call(ej_form,'input');
	var search_params = {};
	for (var i=0;i<conditions.length;i++){
		search_params[conditions[i].id] = conditions[i].value;
	}
	var post_data = _map_get_args(search_params).trim('?');
	d('ej_search_results').className += ' loading';
	d('ej_search_results').innerHTML = 'Loading...';
	do_ajax('/search.php?ejsearch=1',post_data,ej_search_results);
	return false;
}

function ej_search_results(response){
	var result_block = d('ej_search_results');
	result_block.className = (' '+result_block.className+' ').replace(' loading ','');
	result_block.innerHTML = response;
	sorttable.init();
}
function format_numeric_input(e){
	this.value = this.value.replace(/[^\d\.]*/g,'');
}

function stopBubble(e){
     if (navigator.appName.indexOf("Microsoft")!=-1)
        e.cancelBubble = true;
     else
        e.stopPropagation();
}

