// #####################################################################
// 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;
	};
};


// #######################################################################################
// STANDARD FUNCTION FOR POPUP WINDOW
// #######################################################################################
function thisPopup(URL, name, left, top, width, height, scrollbars) {
	var standardSetting = 'toolbar=0, location=1, 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();
	oxl_win = window.open(URL, name, + '\'' + standardSetting + ', ' + customSetting + ', ' + positioning + '\'');
	oxl_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);
}




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




// #####################################################################
// PAYMENT FUNCTIONS
// ####################################################################

var paymentClicked = false;
function paymentWindow(form) {
	var left = 50;
	var top = 50;
	var URL = '';
	var width = 800;
	var height = 580;
	var scrollbars = 1;
	thisPopup(URL, 'payment_window', left, top, width, height, scrollbars);
	document.forms[form].submit();
	paymentClicked = true;
	/*
	if (form == "paypalCheckout") {
		self.location.href="index.php?fcall=paypalEnd";
	}
	*/
	return false;	
}

function checkPaymentStatus() {
	if (paymentClicked) {
		return true;
	} else {
		alert("Please complete your protx transaction before proceeding");
		return false;
	}
}



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

function closePaymentWindow() {
	self.close();
}

function closePaypalWindow() {
	self.close();
}







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


var newSearch = false;
function checkSearchQuery(obj)
{
	if (!newSearch)
	{
		newSearch = true;
		obj.value = '';
	}
}


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

// #####################################################################
// JQUERY STUFF
// ####################################################################

function openSubcategory(categoryId) {
	//hideAllSubcategories();
	$( "#" + categoryId).toggle("slow");
}

function hideAllSubcategories() {
	$(".subcatmenu").each(function(i){
		$(this).hide("fast");
	});
}

// checks valid product combo box options
function checkCombination(id)
{
	$('#' + id ).ajaxSubmit({
             target: '#basket-submit-' + id
          });
	return false;
}


function changeShippingRegion( val )
{
	top.location.href = 'functioncaller.php?fcall=basketSetShippingArea&shipping_region=' + val;
	/*
	$.get("functioncaller.php?fcall=basketSetShippingArea", { shipping_region: val }, function(data){ 
		$('#basket-breakdown-content').html(data);
	} );
	*/
}





