// drop down of order (accounts.php?formaction=order)

function displayorderdiv(order_no, maxheight)
{
	if(document.getElementById('content'+order_no).style.height<maxheight)
	{// its minimized; maximize it
		document.getElementById('table'+order_no).style.display='block';
		document.getElementById('content'+order_no).style.display='block';	
		document.getElementById('content'+order_no).style.height='0px';	
		setTimeout("maximizedisplayorderdiv('"+order_no+"','"+maxheight+"')",'10');
		divi = 0;
	}
	else
	{// its maximized; minimize it	
		minimizedisplayorderdiv(order_no);
	}
}

function maximizedisplayorderdiv(order_no, maxheight)
{
	if(divi<maxheight)
	{// maximize
		divi = divi + 10 ;
		document.getElementById('content'+order_no).style.height= divi+'px';	
		setTimeout("maximizedisplayorderdiv('"+order_no+"','"+maxheight+"')",'10');
	}
	else
	{// maximizing done; change button
		document.getElementById('max'+order_no).innerHTML = '-';
	}
}
function minimizedisplayorderdiv(order_no)
{
	if(divi>0)
	{// minimize
		divi = divi - 10 ;
		document.getElementById('content'+order_no).style.height= divi+'px';	
		setTimeout("minimizedisplayorderdiv('"+order_no+"')",'10');
	}
	else
	{// minimizing done
		document.getElementById('table'+order_no).style.display='none';
		document.getElementById('content'+order_no).style.display='none';
		document.getElementById('content'+order_no).style.height='0px';					
		document.getElementById('max'+order_no).innerHTML = '+';
		
	}
}



// quick popup of product display
function viewProductPopup(prod_code)
{
	document.getElementById('popupinfoframe').src='/traderpro/prod_display.php?formaction=popup_itemdisplay&prod_code='+prod_code;	
	document.getElementById('popupinfodiv').style.display='block';
	document.getElementById('popupinfodiv').style.backgroundColor = "#000000";	
	document.getElementById('popupinfodiv').style.position	= "absolute";
	document.getElementById('popupinfodiv').style.left = "900px";
	document.getElementById('popupinfodiv').style.top = "300px";
	document.getElementById('popupinfodiv').style.width = "10px";
	document.getElementById('popupinfodiv').style.height = "10px";
	varleft = 900 ;
	vartop = 300 ;
	varwidth= 10 ;
	varheight = 10 ;		
	startleft = varleft ;	
	starttop = vartop ;	
	startwidth = varwidth ;
	startheight = varheight ;		
	setTimeout("maximizepopup()", 100);
}
function maximizepopup()
{	
	targetleft = 300 ;
	targettop = 200;
	targetwidth = 600 ;
	targetheight = 400 ;
	
	if(varleft>targetleft) varleft = varleft - ((startleft-targetleft)/10) ;
	if(vartop>targettop) vartop = vartop - ((starttop-targettop)/10);	
	if(varwidth<targetwidth) varwidth = varwidth + ((targetwidth-startwidth)/10) ;
	if(varheight<targetheight) varheight = varheight + ((targetheight-startheight)/10) ;
	
	document.getElementById('popupinfodiv').style.left = varleft+"px" ;
	document.getElementById('popupinfodiv').style.top = vartop+"px";
	document.getElementById('popupinfodiv').style.width = varwidth+"px";
	document.getElementById('popupinfodiv').style.height = varheight+"px";
	if(varleft>targetleft || vartop>targettop || varwidth<targetwidth || varheight<targetheight)
	setTimeout("maximizepopup()", 1);

}

function closeProductPopup()
{
	document.getElementById('popupinfoframe').src='';
	document.getElementById('popupinfodiv').style.display='block';
	document.getElementById('popupinfodiv').style.border = "#ff00ff 4px double";
	document.getElementById('popupinfodiv').style.backgroundColor = "#000000";	
	document.getElementById('popupinfodiv').style.position	= "absolute";
	document.getElementById('popupinfodiv').style.left = "300px";
	document.getElementById('popupinfodiv').style.top = "200px";
	document.getElementById('popupinfodiv').style.width = "600px";
	document.getElementById('popupinfodiv').style.height = "400px";
	varleft = 300 ;
	vartop = 200 ;
	varwidth= 600 ;
	varheight = 400 ;		
	startleft = varleft ;	
	starttop = vartop ;	
	startwidth = varwidth ;
	startheight = varheight ;	
	setTimeout("minimizepopup()", 1);
}

function minimizepopup()
{
	targetleft = 1300 ;
	targettop = 0;
	targetwidth = 1 ;
	targetheight = 1 ;
	
	if(varleft<targetleft) varleft = varleft - ((startleft-targetleft)/10) ;
	if(vartop<targettop) vartop = vartop - ((starttop-targettop)/10);	
	if(varwidth>targetwidth) varwidth = varwidth + ((targetwidth-startwidth)/10) ;
	if(varheight>targetheight) varheight = varheight + ((targetheight-startheight)/10) ;
	
	document.getElementById('popupinfodiv').style.left = varleft+"px" ;
	document.getElementById('popupinfodiv').style.top = vartop+"px";
	document.getElementById('popupinfodiv').style.width = varwidth+"px";
	document.getElementById('popupinfodiv').style.height = varheight+"px";
	if(varleft<targetleft || vartop<targettop) setTimeout("minimizepopup()", 1);
	else 
	{
		document.getElementById('popupinfodiv').style.display='none';
	}
}



// end: quick popup of product display

// function to display which template is being used - admin only

function displaytemplate(target1, target2)
	{
		document.getElementById(target1).style.display = "block";
		document.getElementById(target2).bgColor = "#0099FF";
	}
	function undisplaytemplate(target1, target2)
	{
		document.getElementById(target1).style.display = "none";
		document.getElementById(target2).bgColor = "#ffffff";
	}

// end: function to display which template is being used - admin only

function OpenBasketWindow( targetId )
    {

    
    
    }



    function toggle( targetId )
    {
  	if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  		}
	
	
    
    }
    
    function _toggle( targetId,targetId2 )
    {
  	if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  		}
	
    if (document.getElementById){
  		target2 = document.getElementById( targetId2 );
  			if (target2.style.display == "none"){
  				target2.style.display = "";
  			} else {
  				target2.style.display = "none";
  			}
  		}
	
    
    }
    
    function show( targetId )
    {
  	if (document.getElementById)
        {
  		target = document.getElementById( targetId );
        target.style.display = "";
  		}
    }


    function hide( targetId )
    {
  	if (document.getElementById)
        {
  		target = document.getElementById( targetId );
        target.style.display = "none";
  		}
    }



    
    
function  _refresh_searches (targetId)
{
  	if (document.getElementById)
        {
  		target = document.getElementById( targetId );
        target.submit();

  		}


//setTimeout("refresh_searches.submit()", 10000);
}
    
    
    


   
function _setvalue(id,value) {var ref=document.getElementById(id); if(!ref){ ref=document.createElement('input'); ref.type='hidden'; ref.name=id; ref.id=id; searchform.appendChild(ref); } ref.value=value; }

var csel;
var ccol=-1;
var csub=-1;

function gmover(id) {
	var ref=document.getElementById('g'+id);
	ref.style.borderStyle='outset';
	ref.style.borderWidth=1;
	ref.width=18;
}
function gmout(id) {
	var ref=document.getElementById('g'+id);
	ref.style.borderStyle='none';
	ref.width=20;
}
function gmdown(id) {
	var ref=document.getElementById('g'+id);
	ref.style.borderStyle='inset';
}
function gmup(id) {
	gclick(id);
}
function gclick(id) {
	var ref=document.getElementById('g'+id);
	ref.style.borderStyle='none';
	ref.style.borderWidth=1;
	ref.width=18;
	if(ccol>-1) {
		_setvalue('c'+id,ccol);
		if(ccol==0) {
			ref.style.backgroundImage='URL(/assets/images/33diag.gif)';
			ref.style.backgroundColor='FFFFFF';
		}else{
			ref.style.backgroundColor=document.getElementById('t'+ccol).style.backgroundColor;
			ref.style.backgroundImage='URL()';
		}
	}
	if(csub==20) {
		ref.innerHTML='<img src=/assets/images/user_f.gif width=16 height=16>';
		_setvalue('s'+id,1);
	}
	if(csub==21) {
		ref.innerHTML='<img src=/assets/images/user_fi.gif width=16 height=16>';
		_setvalue('s'+id,0);
	}
	if(csub==22) {
		ref.innerHTML='?';
		_setvalue('s'+id,'');
	}
}

function tmover(id) {
	var ref=document.getElementById('t'+id);
	ref.style.borderStyle='outset';
	ref.style.borderWidth=1;
	ref.width=18;
}
function tmout(id) {
	var ref=document.getElementById('t'+id);
	if(ref==csel) {
		ref.style.borderStyle='solid';
	}else{
		ref.style.borderStyle='none';
		ref.width=20;
	}
}
function tmdown(id) {
	var ref=document.getElementById('t'+id);
	ref.style.borderStyle='inset';
}
function tmup(id) {
	var ref=document.getElementById('t'+id);
	ref.style.borderStyle='outset';
}
function tclick(id) {
	var ref=document.getElementById('t'+id);
	ref.style.borderStyle='outset';
	ref.style.borderWidth=1;
	ref.width=18;
	if(!ref.tag) ref.tag=ref.getAttribute('tag');
	if(id<20) {
		if(ref.tag==document.getElementById('stcol').innerHTML) {
			setcolst('');
			ccol=-1;
		}else{
			setcolst(ref.tag);
			ccol=id;
		}
	}else{
		if(ref.tag==document.getElementById('stsub').innerHTML) {
			setsubst('');
			csub=-1;
		}else{
			setsubst(ref.tag);
			csub=id;
		}
	}
}
function setcolst(str) {
	var ref=document.getElementById('stcol');
	ref.innerHTML=str;
}
function setsubst(str) {
	var ref=document.getElementById('stsub');
	ref.innerHTML=str;
}
function track_check(fn) { return(0);}
function jssubmit() { 	 }


function toggle_tree(id)
{
var plus_img = '/assets/images/expand.gif';
var minus_img = '/assets/images/collapse.gif';

var branch = document.getElementById("c_"+id);


if (branch)
if (branch.style.display == "none")
{
branch.style.display = "block";
img = document.getElementById("i_"+id);
img.src = minus_img;
}
else
{
branch.style.display = "none";
img = document.getElementById("i_"+id);
img.src = plus_img;
}
}

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   string   the element name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, the_element,do_check)
{



    var elts      = (typeof(document.forms[the_form].elements[the_element]) != 'undefined') ? document.forms[the_form].elements[the_element]
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined') ? document.forms[the_form].elements['selected_tbl[]']
                  : document.forms[the_form].elements['selected_fld[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function