function ShowQuickPick(btn, rwid)
{                    
	// Stahe the Button ID in an adhoc document property
	document.tag=btn.id;
	var oWnd = window.radopen(null, rwid);
	oWnd.setUrl(oWnd.get_navigateUrl());
}

// Called when a window is being shown. Good for setting an argument to the window 
function OnClientShow(radWindow)
{                    
  // First get the current product selection
	// pull the Button ID from the adhoc document property
	var btnID = new String();
	btnID = document.tag;

	// trigger can come in through a hyperlink, so transform id to btn to streamline processing
	btnID = btnID.replace("hlQuickPick", "btnQuickPick")
	// find the Hidden ID corresponding to the Button ID
	var hidID = btnID.replace("btnQuickPick", "hidProductGUID")
	// find the element for the Hidden
  var ProductGUID = document.getElementById(hidID);
  // Create a new Object to be used as an argument to the radWindow
  var arg = new Object();                    
  // Using an Object as a argument is convenient as it allows setting many properties.
  arg.ProductGUID = ProductGUID.value;
  // Set the argument object to the radWindow        
  radWindow.Argument = arg;

  var oPos=getWindowPosition();
	radWindow.Center();
}

// Called when a window is being closed.
function OnClientClose(radWindow)
{   
	// pull the Button ID from the adhoc document property
	var btnID = new String();
	btnID = document.tag;

	// trigger can come in through a hyperlink, so transform id to btn to streamline processing
	btnID = btnID.replace("hlQuickPick", "btnQuickPick")
	//alert(btnID);
	
	// find the Hidden and Span IDs corresponding to the Button ID
	var hidID = btnID.replace("btnQuickPick", "hidProductGUID")
	var spnID = btnID.replace("btnQuickPick", "spnProductTitle")
	var chkID = btnID.replace("btnQuickPick", "chkPersonalize")

	// find the elements for the Hidden and Span
  var hidProductGUID = document.getElementById(hidID);
  var spnProductTitle = document.getElementById(spnID);
  var chkPersonalize = document.getElementById(chkID);

  var oArg = radWindow.Argument;

  // update the adjacent ProductGUID (Hidden) and ProductTitle (Span)
  if (oArg && oArg.ProductGUID && oArg.ProductTitle) {
		if (oArg.ProductGUID == '0') {
			hidProductGUID.value = '';
			spnProductTitle.innerHTML = '';
		} else {
		//alert(hidID + ' ' + oArg.ProductGUID);
			hidProductGUID.value = oArg.ProductGUID;
			spnProductTitle.innerHTML = '<strong>' + oArg.ProductTitle + '</strong>';

			if (chkPersonalize) {
				if (oArg.Personalize == "0") {
					chkPersonalize.checked = false;
					chkPersonalize.disabled = true;
				} else {
					chkPersonalize.disabled = false;
				}
			}
		}

		re = new RegExp('.*btnQuickPick_All$');  //generated control name ends with btnID
		//if (btnID == "btnQuickPick_All") {
		if (re.test(btnID)) {
			// this was the global quick picker, so populate all the datagrid controls
			btnID = 'btnQuickPick';
			var str = new String();
			re = new RegExp('.*:' + btnID + '$');  //generated control name starts with a colon
				var frmParent = hidProductGUID.form;
			for(i = frmParent.elements.length-1; i>=0 ; i--) {
				elm = frmParent.elements[i];
				if (elm.type == 'button') {					
					if (re.test(elm.name)) {
						str = elm.id;
						// found a btnQuickPick, now locate its adjacent ProductGUID and ProductTitle
						hidProductGUID = document.getElementById(str.replace("btnQuickPick", "hidProductGUID"));
						hidProductGUID.value = oArg.ProductGUID;
						spnProductTitle = document.getElementById(str.replace("btnQuickPick", "spnProductTitle"));
						spnProductTitle.innerHTML = '<strong>' + oArg.ProductTitle + '</strong>';
						chkPersonalize = document.getElementById(str.replace("btnQuickPick", "chkPersonalize"));
						if (oArg.Personalize == "0") {
							chkPersonalize.checked = false;
							chkPersonalize.disabled = true;
						} else {
							chkPersonalize.disabled = false;
						}
					}
				}
			}
		} else {
			// this was not the global quick picker. just do a courtesy check of the adjacent CheckBox
			var chkID = btnID.replace("btnQuickPick", "chkSelectAddress")
			var chkSelectAddress = document.getElementById(chkID);
			if (chkSelectAddress) {
				if (oArg && oArg.ProductGUID && oArg.ProductTitle) {
					if (oArg.ProductGUID == '0') {
						chkSelectAddress.checked = false;
					} else {
						chkSelectAddress.checked = true;
					}
				}
			}
		}
	}
	document.tag="";
	if (oArg && oArg.AutoPostback) {document.frm.submit();}

}

function getWindowPosition() {
  var myLeft = 0, myTop = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    myTop = window.pageYOffset;
    myLeft = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    myTop = document.body.scrollTop;
    myLeft = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    myTop = document.documentElement.scrollTop;
    myLeft = document.documentElement.scrollLeft;
  }
 
   var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  var oPos = new Object();
  oPos.top = myTop;
  oPos.left = myLeft;
  oPos.width = myWidth;
  oPos.height = myHeight;
  return oPos;
}

