function get_Obj(obj)
{
	var subm=document.getElementById(obj);
	
	return subm;
}
function AreYouSure(Query)
{
	switch(Query) {
		case 1:
			confirmMsg="Sind sie sicher, dass sie den Datensatz entfernen wollen?";
			break;
		case 2:
			confirmMsg="Sind sie sicher, dass sie alle Datens&auml;tze entfernen wollen?";
			break;
		case 3:
			confirmMsg="Sind sie sicher, dass sie das Bild entfernen wollen?";
			break;
		case 4:
			confirmMsg="Sind sie sicher, dass sie diesen Artikel l&ouml;schen m&ouml;chten?";
			break;
	}
   	return confirm(confirmMsg);
}
function ConfirmMsg(Query, URL)
{
   	if(AreYouSure(Query)) window.location.href = URL;
}
function ConfirmTextMsg(Text, URL)
{
   	if(confirm(Text)) window.location.href = URL;
}
function check_agb()
{
   	var agb=get_Obj("agb");
   	var sbm=get_Obj("submit_order");
	if(agb.checked)
	{
		sbm.src="../img/buttons/btn_order2.png";
		sbm.disabled=false;
	}
	else	
	{
		sbm.src="../img/buttons/btn_order2_gray.png";
		sbm.disabled=true;
	}
}

function hidebox(box)
{
	var obj=getObj(box);
	if(obj!=null)
	{
		//obj.style.visibility="hidden";
		obj.style.display="none";
	}
}
function showbox(box)
{
	getObj(box).style.display="inline";//style.visibility="visible";
}

function set_value(dest,value)
{
	get_Obj(dest).value=value;
}

function edit_helptext(obj,text,color1,color2,mode)
{
	if(mode=='IN')
	{
		if(obj.value==text)
		{
			obj.value='';
		}
		obj.style.color=color1;
	}
	else if(mode=='OUT')
	{
		if(obj.value=='')
		{
			obj.value=text;
			obj.style.color=color2;
		}
	}
}

function redirection(URL,time) 
{
	window.setTimeout("do_redirection('"+URL+"')", time);
}

function do_redirection(URL) 
{ 
   location.href=URL; 
}

var currPopup=new Array();

function hidePopup(objDiv)
{
	if(objDiv==null)
	{
		if(currPopup!="")
		{
			currPopup.style.display='none';
		}
		//objDiv=currPopup;
	}
	else if(objDiv!="")
	{
		objDiv.style.display='none';	
	}
}

function showDynBox(divId,x_,y_)
{
	var objDiv=getObj(divId);
	if(window.event!=null)
	{
		x_=x_==undefined ? 0 : x_;
		y_=y_==undefined ? 0 : y_;
		var maus=mausPos(window.event);
		objDiv.style.position='absolute';
		objDiv.style.display='inline';
		objDiv.style.top=maus[1]+y_+'px';//-objDiv.offsetHeight
		objDiv.style.left=maus[0]+x_+'px';//-objDiv.offsetWidth
		currPopup=objDiv;
	}
	else
	{
		objDiv.style.display='inline';
	}
}

function showFixBox(divId)
{
	var objDiv=getObj(divId);
	objDiv.style.display='inline';
}

function hideBox(divId)
{
	var objDiv=getObj(divId);
	objDiv.style.display='none';
}

function divPopup(divId,pid)
{
	pid=pid!=null ? pid : '1';
	var objDiv=getObj(divId);
	if(currPopup!=null && currPopup!=divId)// && pid=='1'
	{
		hidePopup(currPopup);	
	}
	if(pid=='1' && window.event!=null)
	{
		var maus=mausPos(window.event);
		objDiv.style.position='absolute';
		objDiv.style.display='inline';
		objDiv.style.top=maus[1]+'px';//-objDiv.offsetHeight
		objDiv.style.left=maus[0]+'px';//-objDiv.offsetWidth
		currPopup=objDiv;
	}
	else
	{
		objDiv.style.display='inline';
	}
	//if(show)
	//{
	//}
	//else
	//{
	//	hidePopup(objDiv);
	//}
}


			
function strtoint(str)
{
	var i=parseFloat(str.replace(',','.'));
	return str=="" ? 0 : i;
}
function inttostr(i)
{			
	var str=i.toString().replace('.',',');
	return str;
}

function isInt(eingabe)
{
	var num_error = false;
	if(eingabe)
	{
		var eingabe_str = eingabe;
		var num = eingabe_str.match(/[^0-9,\.]/gi);
		var dot = eingabe_str.match(/\./g);
		var com = eingabe_str.match(/,/g);
		if (num!=null)
		{
			num_error = true;
		}
		else if ((dot!=null)&&(dot.length>1))
		{
			num_error = true;
		}
		else if ((com!=null)&&(com.length>1))
		{
			num_error = true;
		}
		else if ((com!=null)&&(dot!=null))
		{
			num_error = true;
		}
	}
	return !num_error;
}			

function int_only(feld)
{
	if(feld.value=="")
	{
		glob_error=true;
		return;
	}
	if(isNaN(feld.value))
	{
		glob_error=true;
		alert("Bitte nur numerische Eingaben!");
		feld.select();
		feld.focus();
		return;
	}
	glob_error=false;
}

function num_only(feld)
{
	if(feld.value == "")
	{
		glob_error=true;
		return;
	}
	var v=feld.value;
	if(v.substr(0,1)=='-')
	{
		v=v.substr(1);
	}
	v=v.replace('.','');
	if(!isInt(v))
	{
		glob_error=true;
		if(v.replace(',', '.').substr(v.length-1,v.length)!='.')
		{
			alert("Bitte nur numerische Eingaben!");
			feld.select();
			feld.focus();
		}
		return;
	}
	glob_error=false;
}

function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}

function formatNumber(obj,KommaStellen)
{
	var value=obj.value;
	if(value!="")
	{
		if(value.indexOf(".")<value.length-KommaStellen-1)
		{
			value=value.replace(".","");			
		}
		//alert(strtoint(value));
		obj.value=number_format(strtoint(value).toFixed(KommaStellen),KommaStellen,',','.');//.toFixed(KommaStellen));
	}
}

function mausPos(e)
{
	var x = e.pageX || window.event.x;
	var y = e.pageY || window.event.y;
	var size=new Array();
	size[0]=x;
	size[1]=y;
	return size;
}


function setRowState(obj,clsId)
{
	var classes=new Array();
	classes[0]="itemList";
	classes[1]="itemList_active";
	classes[2]="itemList_active2";
	classes[3]="itemList_inactive";
	obj.className=clsId!=null ? classes[clsId] : (obj.className==classes[0] ? classes[1] : classes[0]);
}