
var bIsIE   = (document.all) ? true : false;
var bIsDOM  = (document.getElementById) ? true : false;

function findPosX(obj) 
{     
	var curleft = 0;     
	if (obj.offsetParent) 
	{         
		while (obj.offsetParent) 
		{             
			curleft += obj.offsetLeft             
			obj = obj.offsetParent;         
		}      
	} 
	else 
		if (obj.x)         
			curleft += obj.x;     
	
	return curleft; 
}   

function findPosY(obj) 
{     
	var curtop = 0;     
	if (obj.offsetParent) 
	{         
		while (obj.offsetParent) 
		{             
			curtop += obj.offsetTop             
			obj = obj.offsetParent;         
		}      
	} 
	else 
		if (obj.y)         
			curtop += obj.y;     
	
	return curtop; 
}


function adjustDropDownMenus() {

	var MenuWidth = new Array( 83, 42, 0, 0, 279, 30, 0, 0, 0, 0 );
	
	if(bIsIE)
		var StartingPoint = findPosX( document.all.menuanchor );
	else if(bIsDOM)
		var StartingPoint = findPosX( document.getElementById( "menuanchor" ) );
		
	if(bIsIE){
		for( i=1; i<=10; i++ ){
			if( Tmp = eval("document.all.dropdown"+i)){
				Tmp.style.pixelLeft = (StartingPoint += MenuWidth[i-1]);
			}
		}
	}
	else if(bIsDOM) {
		for( i=1; i<=10; i++ ){
			if( document.getElementById( "dropdown"+i ) ){
				document.getElementById( "dropdown"+i ).style.left = (StartingPoint += MenuWidth[i-1]);
			}
		}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) 
		{   v=args[i+2];
			if (obj.style) 
			{
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			
			if (obj.visibility!=v){
            	obj.visibility=v;
				//----------------------------------------------------------------------------------------------------------------------
				// Fixing selects behind dropdown div in IE
                if ( document.all && (args[i]=='dropdown1' || args[i]=='dropdown2') ){
					dropdowns = new Array('ordercriterion_dropdown', 'ordertype_dropdown', 'rowsonpage_dropdown', 'category_dropdown');
					for(j=0; j<dropdowns.length; j++){
						if( args[i]=='dropdown2' && j==2) continue;
						if((obj1=MM_findObj( dropdowns[j] ))!=null)
							obj1.style.visibility=(obj.visibility=='visible')?'hidden':'visible';
					}
                }
				//----------------------------------------------------------------------------------------------------------------------
     }

		}
}

function hideAll(SelectedMenu){
	MM_showHideLayers('dropdown1','','hide','dropdown2','','hide','dropdown3','','hide','dropdown4','','hide','dropdown5','','hide','dropdown6','','hide','dropdown7','','hide','dropdown8','','hide','dropdown9','','hide','dropdown10','','hide');
}

var timerID = null;
var timerOn = false;
var timecount = 200;

var allowDropdown = false;

function startTime() {
	   allowDropdown = true;
       if (timerOn == false) {
              timerID = setTimeout( "hideAll()" , timecount);
              timerOn = true;
       }
}

function stopTime() {
       if (timerOn) {
  	        clearTimeout(timerID);
              timerID = null;
              timerOn = false;
       }
}

window.onresize = adjustDropDownMenus;

function setImgSrc( ImgObj, Filename ){
	if( !ImgObj ) return false;
	ImgObj.src = Filename;
}


function collapseDiv( BoxName, ImgName ){
	if( !(Box = MM_findObj(BoxName)) )
		return false;

	ImgObj = MM_findObj(ImgName);

	if(Box.style.display == "block" || Box.style.display == ""){
		Box.style.display = "none";
		ImgObj.src = "../images/btn_plus.gif";
	}
	else{
		Box.style.display = "block";
		ImgObj.src = "../images/btn_minus.gif";
	}

}

function closeAllTreeDivs( CurrentDiv ){
	var divs = document.getElementsByTagName("div");
	for( var i = 0; i < divs.length; i++){
		if( divs[i].id.substr(0,7) == "treediv" && ( CurrentDiv.lastIndexOf( divs[i].id ) != 0 ) ){
			divs[i].style.display = "none";
			ImgObj = MM_findObj("img" + (divs[i].id.substr(7)));
			if( ImgObj.src != "../images/btn_plus.gif" )
				ImgObj.src = "../images/btn_plus.gif";
		}
	}
}


function setObjectStyle( Object, StyleElement, Value ){
		eval('Object.style.'+StyleElement+' = "'+ Value +'"');
}

function setValue( Object, Value ){
	if( Object ){
		Object.value = Value;
	}
}



function popupWindow( Page, Width, Height ){
	popWindow = window.open( Page,"popWindow","width="+Width+",height="+Height+",scrollbars=1,left="+((screen.width-Width)/2)+",top="+((screen.height-Height)/2)).focus();
}
// ...................................................
// Image enlarger in popup
// ...................................................
function enlargeInPopup( Image, Width, Height ){
		window.open( Image,'','menubar=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,copyhistory=0,width='+Width+',height='+Height+',resizable=0');
}


function handlePCategory(){
	
		document.location = 'index.php?item=2.14.' + document.MainForm.ProdCateg.value;

}

function sendUserAction ( UserAction ){
    document.MainForm.UserAction.value = UserAction;
    document.MainForm.item.value='7';
    document.MainForm.submit();
}

function gotoRecord( RecordIndex, FormName ){
	if( !FormName ) FormName = "TripListForm";
	
	eval("document."+FormName+".StartPosition.value = RecordIndex");
	eval("document."+FormName+".submit()");
}
