// #####################################################################
// defines the browser DOM
// #####################################################################

userAgent = navigator.userAgent;
var NN=0;
var IE=0;
var DOM=0;
if (userAgent.search('MSIE')>=0) {
	IE=1;
} else {
	NN = 1; 
	if (parseInt(navigator.appVersion)>4) {
  		NN=0;IE=1;DOM=1;
	};
};


// #####################################################################
// MOUSE POSITION
// ####################################################################



// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


// #######################################################################################
// STANDARD FUNCTION FOR POPUP WINDOW
// #######################################################################################
function thisPopup(URL, left, top, width, height, scrollbars) {
	var standardSetting = 'toolbar=0, location=0, directories=0, status=0, scrollbars=' + scrollbars;
	var customSetting = 'menubar=0, resizable=1, width=' + width + ', height=' + height;
	var positioning = 'left=' + left + ', top =' + top;
	// create window
	closePopup();
	z_win = window.open(URL, 'myPopup', + '\'' + standardSetting + ', ' + customSetting + ', ' + positioning + '\'');
	z_win.focus();
}

// #######################################################################################
// STANDARD FUNCTION FOR POPUP WINDOW
// #######################################################################################
function thisPopupMenu(URL, left, top, width, height, scrollbars) {
	var standardSetting = 'toolbar=1, location=0, directories=0, status=1, scrollbars=' + scrollbars;
	var customSetting = 'menubar=1, resizable=1, width=' + width + ', height=' + height;
	var positioning = 'left=' + left + ', top =' + top;
	// create window
	closePopup();
	z_win = window.open(URL, 'myPopup', + '\'' + standardSetting + ', ' + customSetting + ', ' + positioning + '\'');
	z_win.focus();
}

// #######################################################################################
// CLOSES POPUP WINDOW IF ALREADY OPEN
// #######################################################################################
function closePopup() {
	if (window.z_win) {
		window.z_win.close();
	}
}

// #######################################################################################
// REFRESHES OPENER
// #######################################################################################
function refreshOpener(URL) {
	window.opener.location.href = URL;
}


// #######################################################################################
//VARIOUS POPUP WINDOW CALLERS
// #######################################################################################
function popupForm(URL, width, height) {
	thisPopup(URL, 100, 120, width, height, 1);
}

function webmilesRight() {
	var URL = "http://www.webmiles.de/app/wm-emptyframe/show/partnerangebote/info.jsp?partner=officexl";
	var left = 20;
	var top = 50;
	var width = 680;
	var height = 490;
	var scrollbars = 1;
	thisPopup(URL, left, top, width, height, scrollbars);
}

// webmiles link on right hand side
function webmilesB2C() {
	var URL = "http://www.webmiles.de/app/wm-gridframe/newuser/edit?partner_id=1195";
	var left = 20;
	var top = 50;
	var width = 300;
	var height = 490;
	var scrollbars = 1;
	thisPopup(URL, left, top, width, height, scrollbars);
}



function showHelp() {
	var URL = "popup_help.php";
	var left = 20;
	var top = 50;
	var width = 600;
	var height = 500;
	var scrollbars = 1;
	thisPopup(URL, left, top, width, height, scrollbars);
}

function printAGB(URL) {
	var left = 20;
	var top = 50;
	var width = 600;
	var height = 500;
	var scrollbars = 1;
	thisPopupMenu(URL, left, top, width, height, scrollbars);
}















// #######################################################################################
// CHANGES BACKGROUND COLOUR OF A TABLE ROW FOR MOUSEOVER
// #######################################################################################
function clrRow(src, newColor) {
	src.bgColor = newColor;
}
// #######################################################################################
// CHANGES BACKGROUND COLOUR OF NAVIGATION TABS FOR MOUSEOVER
// #######################################################################################
function borderCell(src, flag) {
	if (flag) {
		src.style.backgroundColor = "#4B4B4B";
	} else {
		src.style.backgroundColor = "#666666";
	}
}

// #######################################################################################
// RESIZES WINDOW
// #######################################################################################
function resizeWindow(width, height) {
	window.resizeTo(width, height);
}

// #######################################################################################
// zoom image
// #######################################################################################

function zoomImage(URL, width, height, scrollbars) {
	var left = 100;
	var top = 50;
	thisPopup(URL, left, top, width, height, scrollbars);
}





// #####################################################################
// makes a hidden div layer visible
// #####################################################################

var openDiv = '';

function showMe(div) {
	if (openDiv) {
		hideMe(openDiv);
	}
	openDiv = div;	
	if (DOM) {
		document.getElementById(div).style.visibility = 'visible';
		document.getElementById(div).style.display = 'block';
		document.getElementById(div).style.left = 150;
		document.getElementById(div).style.top = yMousePos - 40;
	} else if (IE) {
		document.all[div].style.visibility = 'visible';
		document.all[div].style.display = 'block';
		document.all[div].style.pixelLeft = 150;
		document.all[div].style.pixelTop = yMousePos - 40;
	} else if (NN) {
	    document.div.visibility = 'show';
		document.div.display = 'block';
		document.div.pixelLeft = 150;
		document.div.pixelTop = yMousePos - 40;
	}
} // end function

function showMeExtended(div, offsetleft, offsetTop) {
	if (openDiv) {
		hideMe(openDiv);
	}
	openDiv = div;	
	if (DOM) {
		document.getElementById(div).style.visibility = 'visible';
		document.getElementById(div).style.display = 'block';
		document.getElementById(div).style.left = xMousePos + offsetleft;
		document.getElementById(div).style.top = yMousePos - offsetTop;
	} else if (IE) {
		document.all[div].style.visibility = 'visible';
		document.all[div].style.display = 'block';
		document.all[div].style.pixelLeft = xMousePos + offsetleft;
		document.all[div].style.pixelTop = yMousePos - offsetTop;
	} else if (NN) {
	    document.div.visibility = 'show';
		document.div.display = 'block';
		document.div.pixelLeft = xMousePos + offsetleft;
		document.div.pixelTop = yMousePos - offsetTop;
	}
} // end function



function zoomImage(div) {
	if (openDiv) {
		hideMe(openDiv);
	}
	openDiv = div;	
	if (DOM) {
		document.getElementById(div).style.visibility = 'visible';
		document.getElementById(div).style.display = 'block';
		
	} else if (IE) {
		document.all[div].style.visibility = 'visible';
		document.all[div].style.display = 'block';
	} else if (NN) {
	    document.div.visibility = 'show';
		document.div.display = 'block';
	}
} // end function





	
// #####################################################################
// hides a visible div layer
// ####################################################################
function hideMe(div) {
	if (DOM) {
		document.getElementById(div).style.visibility = 'hidden';
		document.getElementById(div).style.display = 'none';
	} else if (IE) {
		document.all[div].style.visibility = 'hidden';
		document.all[div].style.display = 'none';
	} else if (NN) {
		document.div.visibility = 'hide';
		document.div.display = 'none';
	}
} // end function


// #####################################################################
// collapses div layer
// ####################################################################
function collapseMe(div) {
	if (DOM) {
		document.getElementById(div).style.display = 'none';
	} else if (IE) {
		document.all[div].style.display = 'none';
	} else if (NN) {
		document.div.display = 'none';
	}
	return true;
} // end function

// #####################################################################
// expands collapsible div layer
// ####################################################################
function expandMe(div) {
	if (DOM) {
		document.getElementById(div).style.display = 'block';
	} else if (IE) {
		document.all[div].style.display = 'block';
	} else if (NN) {
		document.div.display = 'block';
	}
	return true;
} // end function


// #####################################################################
// SHOPPING LISTS
// ####################################################################
function addToShoppingList(productID) {
	ajaxShowShoppingListForm(productID);
	if (xMousePos < 500) {
		left = 50;
	} else {
		left = -330;
	}
	showMeExtended("ajaxDiv", left, 150);
}




// #####################################################################
// PAYPAL FUNCTIONS
// ####################################################################

function paypalWindow() {
	var left = 50;
	var top = 50;
	var URL = '';
	var width = 930;
	var height = 580;
	var scrollbars = 1;
	thisPopup(URL, left, top, width, height, scrollbars);
	document.forms["paypalCheckout"].submit();
	return false;	
}

function startInvoiceProcess() {
	resizeWindow(400, 200);
	window.moveTo(400, 300);
	opener.location.href = "invoice.php";
}

function closePaypalWindow() {
	opener.location.href = "invoice.php";
}







function tonershopSubmit(clearModel) {
	myForm = document.forms["tonershop"];
	if (clearModel) {
		myForm.elements["model"].value = "";
	}
	myForm.submit();
}



// #####################################################################
// VOID FUNCTION
// ####################################################################
function voidFunction() {
}











