function Modules(mid){
	$('Navigator').getElements('A').removeClass('Selected');
	$(mid).addClass('Selected');
	var myFx=new Fx.Scroll($(document.body)).set(0,0);
	}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }


function Load_Dropdown(){
	$$('.Dropdown').each(function(item,index){
	
		item.addEvents({
				'focus':function(){
					this.blur();
					var target=this;
					var Options=this.getAttribute('options').split(',');

					if(!$(this.id+'-Dropdown')){
						var OptionsContainer=new Element('ul',{
							'class':'Dropdown',
							'id':this.id+'-Dropdown'
							}).inject(target,'before');
						
						for(i=0;i<Options.length;i++){
							var Option=new Element('li',{
								'html':Options[i],
								'styles':{
									'padding':'5px'
									},
								'events':{
									'click':function(){
										target.value=this.get('html');
										OptionsContainer.dispose();
										},
									'mouseenter':function(){
										this.setStyle('background-color','#eeeeee');
										this.setStyle('color','#1080be');
										},
									'mouseleave':function(){
										this.setStyle('background-color','#ffffff');
										this.setStyle('color','#333333');
										}
									}
								}).inject(OptionsContainer);
	
							}
					}else{
						$(this.id+'-Dropdown').dispose();
						}
					},
					
				'mouseenter':function(){
					this.setStyle('background-position','bottom left');
					this.setStyle('color','#1080be');
					},
					
				'mouseleave':function(){
					this.setStyle('background-position','top left');
					this.setStyle('color','#333333');
					}
			});
	});

}

function Load_Dropdown_Categories(){
	$$('.Dropdown-Categories').each(function(item,index){
	
		item.addEvents({
				'focus':function(){
					//this.blur();
					var target=this;
					var thisOptions=this.getAttribute('options');
					var Options=thisOptions.split('___');

					if(!$(this.id+'-Dropdown')&&thisOptions.length>0){
						var OptionsContainer=new Element('ul',{
							'class':'Dropdown-Categories',
							'id':this.id+'-Dropdown'
							}).inject(target,'before');
						
						for(i=0;i<Options.length;i++){
							var Option=new Element('li',{
								'html':Options[i],
								'events':{
									'click':function(){
										target.value=this.get('html');
										target.setStyle('color','#333333');
										OptionsContainer.dispose();
										},
									'mouseenter':function(){
										this.setStyle('background-color','#eeeeee');
										this.setStyle('color','#1080be');
										},
									'mouseleave':function(){
										this.setStyle('background-color','#ffffcc');
										this.setStyle('color','#333333');
										}
									}
								}).inject(OptionsContainer);
	
							}
					}else{
						if($(this.id+'-Dropdown')){
							  $(this.id+'-Dropdown').dispose();
							  }
						}
					},
				'blur':function(){
					if($(this.id+'-Dropdown')){
						var target=$(this.id+'-Dropdown');
						setTimeout(function(){
							target.dispose();
							},200);
						}
					}
			});
	});

}

function Add_Discount_Rate(iqty,el){
	if(IsNumeric(iqty)&&iqty.length>0){
		var qty = new Number(iqty);
		qty=qty.toFixed(0)
		
		if(el.getElement('tbody[figure='+qty.toFloat()+']')){
			var tbody=el.getElement('tbody[figure='+qty.toFloat()+']');
			tbody.getElement('tr').highlight('#ffffaa');
		}else{
				
				var target=null;
				el.getElements('tbody.Discount-Rate-TR').each(function(item,index){
					var getFigure=item.getAttribute('figure').toInt();
					if(getFigure>qty&&!target){
						target=item;
						}
					});
				
				var PriceListTbody=new Element('tbody',{
					'figure':qty.toFloat(),
					'class':'Discount-Rate-TR'
					});
					
				if(target){
					PriceListTbody.inject(target,'before');
				}else{
					PriceListTbody.inject(el);
					}
					
				var PriceList=new Element('tr',{
					'events':{
						'mouseenter':function(){
							$$('.Price-List-Delete').setStyle('display','none');
							this.getElement('span').setStyle('display','block');
							},
						'mouseleave':function(){
							this.getElement('span').setStyle('display','none');
							}
						}
					}).inject(PriceListTbody);
					
				var PriceListTD=new Element('td',{
					'html':'&nbsp; Buy '+qty+' or above<input name="Item_Price" type="hidden" value="___" /><input name="Item_Price" type="hidden" value="'+qty+'" />',
					'height':'22'
					}).inject(PriceList);
				
				new Element('span',{
					'class':'Price-List-Delete',
					'events':{
						'click':function(){
							if(confirm('You are about to delete this discount rate. Are you sure you want to delete it?')){
								PriceListTbody.dispose();
								}
							}
						}
					}).inject(PriceListTD,'top');
				
				
				for(i=0;i<5;i++){	
					var PriceBox=new Element('td',{
						'align':'center',
						'html':'<input name="Item_Price" type="hidden" value="_" /><input name="Item_Price" type="hidden" value="'+i+'" />'
					}).inject(PriceList);
					new Element('input',{
						'name':'Item_Price',
						'value':'0.00',
						'events':{
							'focus':function(){
								this.select();
								this.setStyle('background-position','bottom left');
								},
							'blur':function(){
								this.setStyle('background-position','top left');
								}
						}
						}).inject(PriceBox);
					}
					
				PriceList.highlight('#ffffaa');
				
			}
		}
	}

function Reload_Notifications(){
	$hx.load('1/Notifications.asp',$('Notifications-Holder'),0);
	}
