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;
 }
}
});

/* This is a workaround for chrome centering JIRA:SIG-5362 & DALMINEX-19 & PLASSONHQ-184*/
jQuery(function()
{
    jQuery(window).resize(function() {
    jQuery(".dialog_search").dialog("option", "position", "center");
    });
});


function submit_search_compl(input_id,kw) {

    var search_url = '/search.php?popup=1&complsearch=1&kw='+encodeURI(kw)+'&pid='+input_id;
    open_in_popup(tg('General search'),search_url,{width:650,height:350}, 'sorttable.init()')
}

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

	var popup = jQuery("<div class=\"dialog_search\"></div>");
	popup.html("<div class='search_results_loading'><h2>Loading...</h2></div>");
	jQuery("body").add(popup);
	popup.dialog({
		title: "General Search",
        width: 'auto',
        height: 'auto',
        position: ['center', 'center'],
		close: function(ev, ui) {
            user_cancel = true; // user clicked close button - don't show results
            jQuery(this).remove(); // don't leave garbage in memory
		}
	});

    jQuery.get(search_url, function(data){
        if (user_cancel) return; // user closed the dialog already...
        popup.dialog('close');
        var maxH = 0.6*jQuery(window).height();
        var maxW = 0.7*jQuery(window).width();
        popup.html("<div style='max-height: "+maxH+"px;max-width: "+maxW+"px;'>" +data+ "</div>");
        popup.dialog({
            title: "General Search",
            width: 'auto',
            height: 'auto',
            close: function(ev, ui) {
                jQuery(this).remove(); // don't leave garbage in memory
            }
        });
        sorttable.init(); //make search results table sortable
    }, 'html');
}

function open_hose(productid){
         window.open('/technical/product/'+productid, 'signaturetech',
           'width=995,height=530,left='+(screen.width / 2 - 350)+ ',top='+(screen.height / 2 - ".(530/2).")+',location=no,menubar=no,toolbar=no,scrollbars=1').focus();
}
function open_overview(productid){
         window.open('/catalogue/product/'+productid).focus();
}

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();
}

