var _updateProgressDiv;
function pageLoad(sender, args) {
	//  register for our events
	if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
		Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
		Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
	}

	_updateProgressDiv = $get('updateProgressDiv');
}

function beginRequest(sender, args) {
	//  get the gridview element
	//var tabContainer = sender._postBackSettings.sourceElement;
	//tabContainer = $get('masterBody');

	// make it visible
	_updateProgressDiv.style.display = '';

	// get the bounds of both the gridview and the progress div
	//var tabContainerwBounds = Sys.UI.DomElement.getBounds(tabContainer);
	//var updateProgressDivBounds = Sys.UI.DomElement.getBounds(_updateProgressDiv);

	//  center of gridview
	//var x = tabContainerwBounds.x + Math.round(tabContainerwBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
	//var y = tabContainerwBounds.y + Math.round(tabContainerwBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);

	//var x = tabContainerwBounds.x;
	//var y = tabContainerwBounds.y;
	//absolute position set to 0,0 in css 
	//_updateProgressDiv.style.width = tabContainerwBounds.width + 'px';
	//_updateProgressDiv.style.height = tabContainerwBounds.height + 'px';
	//width and height are not set to 100% in css

	//	set the progress element to this position
	//Sys.UI.DomElement.setLocation(_updateProgressDiv, x, y);
}

function endRequest(sender, args) {
	// make it invisible
	_updateProgressDiv.style.display = 'none';

	if (args.get_error() != undefined) {
		var errorMessage = args.get_error().message;
		args.set_errorHandled(true);
		//		ToggleAlertDiv('visible');
		//		$get(messageElem).innerHTML = errorMessage;
	}
}
function GeneralErrorPopup(newloc) {
	var ie, winH, winW
	ie = (document.all) ? true : false;
	winW = (ie) ? (document.body.offsetWidth - 20 - 300) / 2 : (window.innerWidth - 16 - 300) / 2;
	winH = (ie) ? (document.body.offsetHeight - 150) / 2 : (window.innerHeight - 150) / 2;
	if (ie) {
		winW = winW + window.screenLeft;
		winH = winH + window.screenTop;
		//newWind=window.open('/appl/generalerror.aspx','Error',"status=no,toolbar=no,scrollbars=no,directories=no,location=no,resizable=on,width=300,height=150,top=" + winH + ",left=" + winW);
		newWind = WindowOpen('/appl/generalerror.aspx', 'Error', 300, 150);
	} else {
		winW = winW + window.screenX;
		winH = winH + window.screenY;
		//newWind=window.open('/appl/generalerror.aspx','Error',"status=yes,toolbar=no,scrollbars=no,directories=no,location=no,resizable=on,width=300,height=150,screenY=" + winH + ",screenX=" + winW);
		newWind = WindowOpen('/appl/generalerror.aspx', 'Error', 300, 150);
	}
	window.location = newloc;
	return (true);
}
function GeneralErrorPopupChild(newloc) {
	var ie, winH, winW
	ie = (document.all) ? true : false;
	winW = (ie) ? (document.body.offsetWidth - 20 - 300) / 2 : (window.innerWidth - 16 - 300) / 2;
	winH = (ie) ? (document.body.offsetHeight - 150) / 2 : (window.innerHeight - 150) / 2;
	if (ie) {
		winW = winW + window.screenLeft;
		winH = winH + window.screenTop;
		//newWind=window.open('/appl/generalerror.aspx','Error',"status=no,toolbar=no,scrollbars=no,directories=no,location=no,resizable=on,width=300,height=150,top=" + winH + ",left=" + winW);
		newWind = WindowOpen('/appl/generalerror.aspx', 'Error', 300, 150);
	} else {
		winW = winW + window.screenX;
		winH = winH + window.screenY;
		//newWind=window.open('/appl/generalerror.aspx','Error',"status=yes,toolbar=no,scrollbars=no,directories=no,location=no,resizable=on,width=300,height=150,screenY=" + winH + ",screenX=" + winW);
		newWind = WindowOpen('/appl/generalerror.aspx', 'Error', 300, 150);
	}
	window.opener.location = newloc;
	window.close();
	return (true);
}

function WindowOpen(URL, windowName, width, height) {
	return WindowOpen2(URL, windowName, width, height, false, false, false, false, false, false, true);
}

function ShowProductDetailPage(id) {
	ShowProductDetailPage(id, 0);
}
function ShowProductDetailPage(id, iss) {
	ShowProductDetailPage(id, 0, false);
}
function ShowProductDetailPage(id, iss, readonly) {
	var url;
	url = '/appl/catalog/productdetail.aspx?productid=' + id;

	if (iss == 1)
		url = url + '&iss=';

	if (readonly)
		url = url + "&readonly=";

	window.location = url;

	return (false);
}


function WindowOpen2(URL, windowName, width, height, status, toolbar, location, menubar, directories, resizable, scrollbars) {
	var windowFeatures = '';
	if (status)
		windowFeatures += 'status,';
	if (toolbar)
		windowFeatures += 'toolbar,';
	if (location)
		windowFeatures += 'location,';
	if (menubar)
		windowFeatures += 'menubar,';
	if (directories)
		windowFeatures += 'directories,';
	if (resizable)
		windowFeatures += 'resizable,';
	if (scrollbars)
		windowFeatures += 'scrollbars,';

	if (width != '' && width != null) {
		windowFeatures += 'width=' + width + ',';
		var left = (window.screen.width / 2) - (width / 2);
		windowFeatures += 'left=' + left + ',';
	}

	if (height != '' && height != null) {
		windowFeatures += 'height=' + height + ',';
		var top = (window.screen.height / 2) - (height / 2);
		windowFeatures += 'top=' + top + ',';
	}

	return WindowOpenWithPopupBlockerCheck(URL, windowName, windowFeatures, true);
}

function WindowOpenWithPopupBlockerCheck(URL, windowName, windowFeatures, CheckPopupBlocker) {
	var wndPopup = window.open(URL, windowName, windowFeatures);
	if (CheckPopupBlocker && !wndPopup)
		alert('A popup blocker may be preventing ' + GetServer_Name() + ' from opening the page. If you have a popup blocker, try disabling it to open the window.');
	else
		wndPopup.focus();

	return wndPopup;
}


function GetServer_Name() {
	var x = window.location.href.split('/');
	x.length = 3;
	return x.join('/');
}

//onkeypress="return isDigit(event,'decOK');
//onkeypress="return isDigit(event,'noDec');
function onlyDigits(e, decReq) {
	//var isIE = document.all?true:false;
	//var isNS = document.layers?true:false;

	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 58) ? true : false;
	var dotOK = (key == 46 && decReq == 'decOK' && (obj.value.indexOf(".") < 0 || obj.value.length == 0)) ? true : false;

	if (key < 32)
		return true;
	return (isNum || dotOK);
}
function IsPageMode() {
	return (window.opener != null);
}
function ShowContractSelection(ProductId, CatalogID, Mode) {
	WindowOpen('/appl/software/search/selectcontract.aspx?ProductID=' + ProductId + '&CatalogID=' + CatalogID + '&Mode=', 'SelectContract', 600, 250);
	return false;
}
function OnPinPointeSearch(kwQuickId) {
	var kw = document.getElementById(kwQuickId);
	OnPinPointeSearch2("kw=" + kw.value);
	return false;
}
function OnPinPointeSearch2(kw) {
	var isPageValid = kw != "" && kw != "kw=" && kw != "Enter keyword, part#, etc." && kw != "kw=Enter keyword, part#, etc.";
	if (isPageValid) {
		var strURL = '/appl/catalog/searchresults.aspx?Stat=Pin&' + kw.substring(0, kw.indexOf('=') + 1) + escape(kw.substring(kw.indexOf('=') + 1).replace('<', '&lt;')).replace('+', '%2b').replace('/', '%2f').replace('@', '%40');
		window.location = strURL;
	}
}
function OnPinPointeAutoCompleteSelected(sender, e) {
	OnPinPointeSearch2(e.get_value());
}
function PopupWindowCantFind() {
	try {
		WindowOpen('/appl/catalog/cantfindit.aspx', 'CantFintIt', 500, 640);
	}
	catch (ex) {
		WindowOpen('/appl/catalog/cantfindit.aspx', '', 500, 640);
	}
}
function logout() {
	var answer = confirm("Are you sure you want to logout?")
	if (answer) {
		window.location = "/logout.aspx";
	}
}
function maxSizeImage(theImg, maxWidth, maxHeight) {
	var hDiff = 0;
	var wDiff = 0;

	var tempImg = new Image();
	tempImg.src = theImg.src;

	hDiff = tempImg.height - maxHeight;
	wDiff = tempImg.width - maxWidth;

	if (hDiff > 0 && hDiff > wDiff) {
		theImg.width = tempImg.width * (maxHeight / tempImg.height);
		theImg.height = maxHeight;
	}
	else {
		if (wDiff > 0 && wDiff >= hDiff) {
			theImg.height = tempImg.height * (maxWidth / tempImg.width);
			theImg.width = maxWidth;
		}
	}
}
function trim(str) {
	str = this != window ? this : str;
	return str.replace(/^\s+/, '').replace(/\s+$/, '');
}
function stripHTML(oldString) {
	return oldString.replace(/(<([^>]+)>)/ig, "");
}
function ShowHideRefinePanel(ControlToExpand, Btn, ExpandedImageToolTip, ExpandedImageUrl, CollapsedImageToolTip, CollapsedImageUrl) {
	var oControlToExpand = document.getElementById(ControlToExpand);
	var oBtn = document.getElementById(Btn);
	if (oControlToExpand != null && oBtn != null) {
		if (oControlToExpand.style.display == "") {
			oBtn.title = ExpandedImageToolTip;
			oBtn.src = ExpandedImageUrl;
			oBtn.alt = ExpandedImageToolTip;
			oControlToExpand.style.display = "none";
		}
		else {
			oBtn.title = CollapsedImageToolTip;
			oBtn.src = CollapsedImageUrl;
			oBtn.alt = CollapsedImageToolTip;
			oControlToExpand.style.display = "";
		}
	}
	return false;
}

function ShowHideRefinePanelWithClientHandel(ClientHandelToExpand, Btn, ExpandedImageToolTip, ExpandedImageUrl, CollapsedImageToolTip, CollapsedImageUrl) {
	var oBtn = document.getElementById(Btn);
	if (oBtn != null) {
		var btnSource = String(oBtn.src);
		if (btnSource.indexOf(ExpandedImageUrl) >= 0) {
			bDoExpand = false;
			oBtn.title = CollapsedImageToolTip;
			oBtn.src = CollapsedImageUrl;
			oBtn.alt = CollapsedImageToolTip;
		}
		else {
			bDoExpand = true;
			oBtn.title = ExpandedImageToolTip;
			oBtn.src = ExpandedImageUrl;
			oBtn.alt = ExpandedImageToolTip;
		}
	}
	var funcCall = ClientHandelToExpand + "('" + bDoExpand + "');";
	eval(funcCall);
	return false;
}

