// JavaScript Document
function ___search(){
	var choose = document.searchfrm.choose.value;
	var keyword = document.searchfrm.keyword.value;
	var category = document.searchfrm.category.value;
	var supply = document.searchfrm.supply.value;
	var price = document.searchfrm.price.value;
	var linkpath='./?show=search&choose='+choose+((keyword!='') ? '&key='+keyword:'');
	if(choose<2){
		linkpath += '&cgy='+category+'&spl='+supply+'&prc='+price;
	}
	document.location.href=linkpath;
}
function load_supply_list(){
	if(supply_list==null){
		return false;
	}
	else{
		var obj = document.searchfrm.supply;
		if(remove_listbox(obj)){ 
			var category_id = document.searchfrm.category.value;
			var index=0;
			for(var i=0; i < supply_list.length; i++){
				if(supply_list[i][0]==category_id){
					index++;
					var text = supply_list[i][2];
					obj.options[index] =  new Option(text, supply_list[i][1]);
				}	
			}
			if(obj.options.length>1){
				obj.options[1].selected=true;
			}
		}
	}
}
function remove_listbox(obj){
	while(obj.length != 1){
		obj.remove(1);
	}
	return true;	
}
function ___chooseSearch(obj){
	if(document.getElementById('searchArea')!=null){
		document.getElementById('searchArea').style.visibility=((obj.value<2) ? 'visible':'hidden');
	}
}
function ___advertise(linkpath){
	if((linkpath!='')&&(linkpath!='#')){
		window.open(linkpath,"Advertise");
	}
}
function ___news(id){
	document.location.href='./?show=newsdetail&id='+id;
}
/*___supply(11, 0, false)*/ 
function ___supply(id, category_id, sparepart){
	document.location.href='./?show='+(!sparepart ? 'prosupply':'sppsupply')+'&spl='+id+'&cgy='+category_id;
}
function ___product(act){
	document.location.href='./?show=products&flr='+act;
}
function ___detail(id){
	document.location.href='./?show=prodetail&id='+id;
}
function ___sppdetail(id){
	document.location.href='./?show=sppdetail&id='+id;
}
function ___searchdetail(id,choose){
	var ichoose = parseInt(choose);
	switch(ichoose){
		case 0:{document.location.href='./?show=prodetail&id='+id;break;}
		case 1:{document.location.href='./?show=sppdetail&id='+id;break;}
		default:{document.location.href='./?show=newsdetail&id='+id;break;}
	}
}
function ___submenu(id){
	if(document.getElementById(id+'sub')!=null){
		document.getElementById(id+'sub').style.display='block';
	}
}
function ___printnew(id){
	window.open('./printer.php?id='+id,"PRINTER");
}
function ___sendmail(id){
	document.location.href='./?show=sendnews&id='+id;
}

var last_click;             // zuletzt angeklickter Button
var windows = new Array();  // Array mit Win-Objekten
function Win(ref, posx, posy) {
   this.ref  = ref;
   this.posx = posx;
   this.posy = posy;
}
function check_windows() {
   windows_new = new Array();
   for (i=0; i<windows.length; i++)
   {
    var found = false;
    try{
        if(!windows[i].ref.closed)
            found = true;
    }
    catch(e){
        found = false;
    }
    if (found && windows[i] && windows[i].ref && !windows[i].ref.closed) {
         windows_new.push(windows[i]);
         windows[i].ref.focus();
      }
   }
   windows = windows_new;
}

function window_open(url, w_width, w_height, scroll, type) {
   check_windows();
   ind = windows.length - 1;
   if (windows[ind]) {
      posx = windows[ind].posx + 20;
      posy = windows[ind].posy + 20;
   }
   else {
      posx = (screen.width - w_width) / 2;
      posy = (screen.height - w_height) / 2 - 30;
   }
   if (type == 'resizeable')  proper = 'titlebar=no,toolbar=yes,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'normal')      proper = 'titlebar=no,toolbar=no,menubar=no,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'menu')        proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'mresizeable') proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=yes,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
   if (type == 'minimized')   proper = 'titlebar=no,toolbar=no,menubar=yes,scrollbars='+scroll+',width='+w_width+',height='+w_height+',resizable=no,left='+screen.width+',top='+screen.height+',screenX='+screen.width+',screenY='+screen.height;
   

   win_ref = window.open(url, '', proper);
   if (win_ref) {
      tmp = new Win(win_ref, posx, posy);
      windows.push(tmp);
      win_ref.focus();
   }
   return win_ref;
}

function modal_open(url, w_width, w_height, scroll, type) {
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}

function modless_open(url, w_width, w_height, scroll, type) {
   if (type == 'normal')     proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:no;scroll:'+scroll+';status:no;';
   if (type == 'resizeable') proper = 'dialogHeight:'+w_height+'px;dialogWidth:'+w_width+'px;center:yes;edge:raised;help:no;resizable:yes;scroll:'+scroll+';status:no;';
   window.showModalDialog(url, window, proper);
}
function thumbnail(pathlink, w, h){
	if((parseInt(w) > 0)&&(parseInt(h) > 0)){
		if(parseInt(w) > screen.width)
			w = screen.width;
		if(parseInt(h) > screen.height)
			h = screen.height;
		window_open(pathlink, w, h,'yes','normal');
	}
}
function ___isnumber(obj){
	obj.value = ___number(obj.value);
}
function ___number(str){
	for(var i=0; i<str.length; i++){
		var c = str.charAt(i);
		if ((c<'0') || (c>'9'))
			return str.substr(0, i);
	}
	return str;
}
function ___email(obj){
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	return emailRegExp.test(obj.value);
}