<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title></title>
	
	<!--MqRelPath--><link rel="stylesheet" title="silver" type="text/css" href="../../theme/css/censusmain.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" title="silver" type="text/css" href="<BASE_VD>/theme/css/censusmain.css"/></MqAbsPath-->
	<!--MqRelPath--><link rel="stylesheet" title="silver" type="text/css" href="../../theme/css/mqwizard.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" title="silver" type="text/css" href="<BASE_VD>/theme/css/mqwizard.css"/></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqsysutils.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqsysutils.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqsysmsg.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/window.js" ></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.js" ></script></MqAbsPath-->
	
	<!--MqRelPath--><link rel="stylesheet" href="../../js/jquery/jquery.ui.all.css"><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" href="<BASE_VD>/js/jquery/jquery.ui.all.css"></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery-1.7.1.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery-1.7.1.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.bgiframe-2.1.2.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.bgiframe-2.1.2.js"></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.core.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.core.js"></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.widget.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.widget.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.mouse.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.mouse.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.draggable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.draggable.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.position.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.position.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.resizable.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.resizable.js"></script></MqAbsPath-->
		<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery.ui.dialog.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.dialog.js"></script></MqAbsPath-->
		

	<script type="text/javascript">
		// always define this object for the system messages
		var objSysMsg = new CMqSysMsg();
		var m_objMqButton = new MqButton();
		
		var m_objRef;
		
		if(opener){
			if(opener.parent){
				m_objRef=opener.parent;
			}
		}else{
			if(parent){
				m_objRef=parent;
			}
		}
		
		var m_strMsgTitle="";
		var m_strMsgContent="";
		
		function OnLoad(){
			
			var objNewAsset=document.getElementById("txtNewAsset");
			
			if(objNewAsset){
				objNewAsset.focus();
			}
			return true;
		}

		function cmdOK_OnClick(blnCloseAfterSave)
		{
			//assumption: you can only exchange an asset that is assigned with one in storage
			var objOldAsset=document.getElementById("txtOldAsset");
			var objNewAsset=document.getElementById("txtNewAsset");
			var strURL="";
			var strDelim=";";
			
			if(objOldAsset && objNewAsset){
				if(m_objRef){
					var strSN=objOldAsset.value;
					var strAvailableWhere="Asset_Sub_status=1";//assigned
					strURL="UF=" + g_MqRef.MqStr.MqEncodeURIComponent("Serial_Number;Asset_Tag") + 
							"&UV=" + g_MqRef.MqStr.MqEncodeURIComponent(strSN) + 
							"&UW=" + g_MqRef.MqStr.MqEncodeURIComponent(strAvailableWhere) + 
									"&ID=" + g_MqRef.MqStr.MqEncodeURIComponent(strDelim) +
									"&OD=" + g_MqRef.MqStr.MqEncodeURIComponent(strDelim);
					
					var co = m_objRef.objRequest.Post(m_objRef.mstrCurrentLocation + "../ASP/GetIDs.asp", strURL);
					if (co!=""){
						var arrResults=co.split("*|*");
						
						var arrOldIDs=arrResults[0].split(strDelim);
						var strOldID=arrOldIDs[0];
						var strNotFound=arrResults[2];
						var strNotAvailable=arrResults[3];
						var strMsg="";
						if(strNotFound=="" && strNotAvailable==""){
							strSN=objNewAsset.value;
							strAvailableWhere="Asset_Sub_status=2";//In Storage
							strURL="UF=" + g_MqRef.MqStr.MqEncodeURIComponent("Serial_Number;Asset_Tag") + 
									"&UV=" + g_MqRef.MqStr.MqEncodeURIComponent(strSN) + 
									"&UW=" + g_MqRef.MqStr.MqEncodeURIComponent(strAvailableWhere) + 
									"&ID=" + g_MqRef.MqStr.MqEncodeURIComponent(strDelim) +
									"&OD=" + g_MqRef.MqStr.MqEncodeURIComponent(strDelim);
							var co = m_objRef.objRequest.Post(m_objRef.mstrCurrentLocation + "../ASP/GetIDs.asp", strURL);
							if (co!=""){
								var arrResults=co.split("*|*");
								var arrNewIDs=arrResults[0].split(strDelim);
								var strNewID=arrNewIDs[0];
								var strNotFound=arrResults[2];
								var strNotAvailable=arrResults[3];
								
								
								if(strNotFound=="" && strNotAvailable==""){
									if(m_objRef.m_objCheckInOutAdptr){
										m_objRef.m_objCheckInOutAdptr.setExchangeAsset(strNewID, strSN, objOldAsset.value);
									}
									OpenCheckIn(strOldID);
									CloseWindow();
								}else{
									if(strNotFound!=""){
										strMsg=g_MqRef.MqStr.FormatString(g_MqRef.RESX["MSG_SN_NOT_FOUND"], strNotFound);
									}else{
										if(strNotAvailable!=""){
											strMsg=g_MqRef.MqStr.FormatString(g_MqRef.RESX["MSG_NOT_FOR_EXCHANGE_NEW"], strNotAvailable);
										}
									}
									if(strMsg!=""){
										g_MqRef.AlertBox.show(g_MqRef.RESX["TITLE_CANT_EXCHANGE"], strMsg);
									}
								}
							}
								
						}else{
							if(strNotFound!=""){
								strMsg=g_MqRef.MqStr.FormatString(g_MqRef.RESX["MSG_SN_NOT_FOUND"], strNotFound);
							}else{
								if(strNotAvailable!=""){
									strMsg=g_MqRef.MqStr.FormatString(g_MqRef.RESX["MSG_NOT_FOR_EXCHANGE_OLD"], strNotAvailable);
								}
							}
							if(strMsg!=""){
								g_MqRef.AlertBox.show(g_MqRef.RESX["TITLE_CANT_EXCHANGE"], strMsg);
							}
						}
					}
				}			
			}
		}
		
		function OpenCheckIn(strID)
		{
			if(strID!=""){
				m_objRef.LoadRecord(strID, -1, false);
			}else{
				alert(g_MqRef.RESX["MSG_NO_ASSETS_FOUND_CHECKOUT_MULTIPLE"]);
			}
		}
		
		function KeyPressed(e, strSrcField)
		{
			if(e.keyCode == 13){
				if(strSrcField=="txtNewAsset"){
					var objOldAsset=document.getElementById("txtOldAsset");
			
					if(objOldAsset){
						objOldAsset.focus();
					}
				}else{
					cmdOK_OnClick(true);
				}
			}
		}
	</script>
</head>

<body id="frmMain" name="frmMain" class="MainBackgroundPopup" 
style="margin:0;" leftmargin="0" rightmargin="0" 
onload="OnLoad();" bottommargin="0" scroll="no">

	<div class="TopToolBarPopup">
		<table width="98%" class="TopToolBarWizard">
			<tr>
				<td>
					<img src="../../theme/images/images/telcom.png" width="48" height="48" />
				</td>
		        <td valign="top" style="padding-top:15px; padding-left:10px" width="100%">
		            <div class="WizardTitle"><script type="text/javascript">document.write(g_MqRef.RESX["SCAN_EXCHANGE_ASSETS_TITLE"]);</script></div>
		            <div class="WizardDescription"><script type="text/javascript">document.write(g_MqRef.RESX["SCAN_EXCHANGE_ASSETS_DESC"]);</script></div>
		        </td>
		    </tr>
		</table>
	</div>

	<table id="tblMain" marginwidth="0" cellspacing="0" cellpadding="0" border="0" style="padding-left:30px;width: 98%;" >
		<tr >
			<td align="left" style="padding-top: 15px;pad-ding-bottom: 15px;" class="MainBackgroundPopup">
				<script type="text/javascript">document.write(g_MqRef.RESX["EXCHANGE_ASSETS_OUT"]);</script>
			</td>
			<td rowspan="4" width="100" style="text-align:right; padding-top:20px;">
				<img src="../../theme/images/images/exchangeassets_big.gif" width="80" height="80" />
			</td>
		</tr>
		<tr>
			<td>
				<input type="text" name='txtNewAsset' id='txtNewAsset' class='TextBoxWidth' style="width:98%" onkeyup="KeyPressed(event, 'txtNewAsset');"></input>
			</td>			
		</tr>
		<tr >
			<td align="left" style="padding-top: 15px;pad-ding-bottom: 15px;" class="MainBackgroundPopup">
				<script type="text/javascript">document.write(g_MqRef.RESX["EXCHANGE_ASSETS_IN"]);</script>
			</td>
			
		</tr>
		<tr>
			<td>
				<input type="text" name='txtOldAsset' id='txtOldAsset' class='TextBoxWidth' style="width:98%" onkeyup="KeyPressed(event, 'txtOldAsset');"></input>
			</td>			
		</tr>
		
	</table>
	<table align="right" style="padding-right:10px;padding-top:40px">
		<tr>
			<td align=right>
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("Next", g_MqRef.RESX["BUTTON_NEXT"], 'cmdOK_OnClick(true)', "", 32, "", g_MqRef.RESX["BUTTON_NEXT"], 90);</script>
			</td>
			<td align=right>
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CLOSE"], 'CloseWindow()', "", 32, "", g_MqRef.RESX["BUTTON_CLOSE"], 90);</script>
			</td>
		</tr>
		</tbody> 
	</table>
	
</body>
</html>