function load_image(){
	 var pic = new Array();
	 var items = load_image.arguments;
	 
	 for( i = 0 ; i < items.length; i++ ){
	 	pic[i] = new Image(); 
	 	pic[i].src = items[i]; 
	 }
}

load_image( "/images/meny_bg.jpg" , "/images/meny_select_bg.jpg" , "/images/menygraa_bg.jpg" , "/images/menysvart_bg.jpg" );

/*
*	Detect type DOM
*/

function findDOM( objectID, withStyle){
	if( withStyle){
		if( document.getElementById) 
			return ( document.getElementById( objectID ).style);
		else if( document.all )
			return ( document.all[ objectID ].style);
		else if( (navigator.appName.indexOf('Netscape') != -1) && ( parseInt(navigator.appVersion) == 4 ) )
			return (document.layers[ objectID]);
	}else{
		if( document.getElementById) 
			return ( document.getElementById( objectID ));
		else if( document.all )
			return ( document.all[ objectID ]);
		else if( (navigator.appName.indexOf('Netscape') != -1) && ( parseInt(navigator.appVersion) == 4 ) )
			return (document.layers[ objectID]);	
	}
}


/*
* MOUSE begin
*/
var IE = document.all?true:false;
document.onmousemove = getMouseXY;
document.onmousedown = getMouseXY;
document.onmouseup = MouseUp;

function MouseUp(){
	ErrorDrop();	
}

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  ErrorMove();

  return true
}

/*
* MOUSE end
*/

/*************************************************
*	BEGIN explanation
*************************************************/
function setDisplay( id , status ){
	var elm = findDOM( id , true );
	elm.display = status;
}
/*************************************************
*	END explanation
*************************************************/

function showBgColor( obj ){
	obj.style.background = "#eeeeee";
}

function hiddenBgColor(obj){
	obj.style.background = "";
}

if(document.all)document.getElementById=document.all;

function switchVisibility(elm) {
	//alert(elm.parentNode.tagName);
	var ULelm;

	for (i = 0; i < elm.parentNode.childNodes.length; i++) {
		ULelm = elm.parentNode.childNodes[i];
		if (ULelm.tagName == 'UL') break;
	}


 	if(ULelm && (ULelm.tagName == 'UL')) {
		ULelm.style.display = (ULelm.style.display == "none") ? "block" : "none";
		elm.className = (elm.className == "linkCollapsed") ? "linkExpanded" : "linkCollapsed";
	}
	
}

function validNubmer( obj ){
	var nValue = obj.value;
	
	format_nValue = /^([0-9]+)([0-9]*)(\.|,)?([0-9]{0,2})$/;
	if( format_nValue.test( nValue )== false){
		
		result = format_nValue.test( nValue );
		format_out = /(\.|[0-9]|,)/;
		format_replace = /[^0-9.,]/;
		outtext= '';
		//alert(nValue.length);
		//for( i=0 ; i< nValue.length ; i++){
			//if( format_out.test( nValue[i] ) ){
			//	outtext = outtext + nValue[i];
			//}
			
			//alert(nValue[i]);
		//}	
		obj.value = obj.value.replace( format_replace , '' );
	}
	
}

function setHiddenToSelect( obj_select ){
	//alert( obj_select.options[ obj_select.selectedIndex ].value );
	var arguments = setHiddenToSelect.arguments;
	
	if( obj_select.options[ obj_select.selectedIndex ].value == '0'){
		disabled = true;
		//document.FormProduct.PriceExpress.disabled = true;//alert( obj_select.options[ obj_select.selectedIndex ].value );
	}else{
		disabled = false;
		//document.FormProduct.PriceExpress.disabled = false;
	}
	
	for( i=1 ; i<= arguments.length ; i++){
		setDisabled( arguments[i] , disabled );
	}
}

function setDisabled( obj , disabled ){
		eval( obj +'.disabled ='+ disabled +';');
}

var field;

function setField( $obj ){
	field = $obj;	
}

function insertCode(code) {
  // Internet Explorer	
  if (field.createTextRange && field.caretPos) {
    field.caretPos.text = code;
  }
  // Mozilla
  else if (field.selectionEnd) {
    selLength = field.textLength;
    selEnd = field.selectionEnd;
    s1 = (field.value).substring(0, selEnd)
    s2 = (field.value).substring(selEnd, selLength);
    field.value = s1 + code + s2;
    newSelEnd = parseInt(selEnd)+parseInt(code.length);
    field.setSelectionRange(newSelEnd, newSelEnd);
  }
  // other browsers
  else {
    field.value = field.value + code;
  }
  field.focus();
}


/*****************************************************************
*	image
******************************************************************/
window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);

function getImagePageLeft(img) {
  var x, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  if (IE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    return x;
  }
  return -1;
}

function getImagePageTop(img) {
  var y, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (IE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    return y;
  }
  return -1;
}

/*****************************************************************
*	search
*****************************************************************/
function switchVisibilitySearch( _id ){
	var fieldset = findDOM( _id ) ;
	if( fieldset )
		fieldset.id =  _id + 'Show' ;
	else
		findDOM( _id + 'Show' ).id = _id ;
}


function checkAll(_cbObject, _cbGroupName) {

	if(_cbObject) {

		var _formObject	= _cbObject.form;

		if(_formObject) {

			var _elements	= _formObject.elements;

			if(_elements) {

				var _i;
				var _totalCnt	= _elements.length;
				var _currElement;

				var _newStatus	= _cbObject.checked ? true : false;

				for(_i = 0; _i < _totalCnt; _i++) {

					_currElement	= _elements[_i];

					if(_currElement) {
						if(_cbGroupName) {
                            var reg = new RegExp( "^"+  _cbGroupName +"");
                            
							if(_currElement.type == 'checkbox' && ( _currElement.name == _cbGroupName || reg.test( _currElement.name ) ) ) {
								_currElement.checked	= _newStatus;
							}
						} else {
							if(_currElement.type == 'checkbox') {
								_currElement.checked	= _newStatus;
							}
						}
					}
				}
			}
		}
	}
}


Number.prototype.roundDecimal = function( decimals ){
    num = this;
    if( decimals && num ){
        num = Math.round( num * Math.pow( 10,decimals) ) / Math.pow( 10,decimals) ;
    }
    return num;
}

/**
 *	Format number
 *
 *	@var string dec_point
 *  @var string thousands_sep
 *	@return string
 */
Number.prototype.format = function( dec_point, thousands_sep, decimals ){
    
    dec_point = dec_point || ',' ;
    decimals = decimals || 0 ;
    
    var splitNum = this.roundDecimal( decimals ).toString().split(/[\.,]/);
	var s_num = splitNum[0];
    var d_num = splitNum[1] || '';
	var out_num = '';

    if( ( d_num.length || 0 ) < decimals ){
        d_num = d_num +  "0".times( decimals - ( d_num.length || 0 ) );
    }
    
	if( thousands_sep ){
        while( s_num ){
           
			out_num = s_num.substr(  ( s_num.length - 3 < 0 ) ? 0 : s_num.length - 3 )  + ( thousands_sep || '' ) + out_num;
            
			s_num = s_num.substr( 0 , s_num.length - 3 );
            
		}

        out_num = out_num.substr( 0, out_num.length - 1 );
	} else {
        out_num = s_num;
    }
    
	return out_num + ( d_num && ( dec_point + d_num ) ) ;
}

