/**************************************************************************************
 * File Name	:	mydevices.js
 * Description	:	This file contains the functions which is used for the My Devices section in the SMBSA portal.
 *
 * Modification Log
 * Ver		Date		   Author                       Description
 * ----------------------------------------------------------------------------
 * 0.00a  	5-Jan-2005        tsamadde			Initail Draft
 * 1.00		13-Jul-2005		  bdebroy			Adding a funtion to inplement Download to Excel
 * 1.01		26-Aug-2005		  bdebroy			Modified a function for SMBSA 1.2 and TSRT integration
 **************************************************************************************/
 
//******************************************************************************
// Function Name		:	fnSortResults
// Created Date			:	5-Jan-2005
// Description			:	Set the sort column and sort order 
// Input Parameters		:	sortBy- the column to be sorted 
//							sortOrder-asc or desc as per the arrow clicked,
//							sortAction-The url which it should go to on click
// Output Parameters	:   None
//******************************************************************************

function fnSortResults(sortBy, sortOrder,sortAction)
{
	document.SmbsaHomeForm.sortBy.value=sortBy;
	document.SmbsaHomeForm.sortOrder.value=sortOrder;
	document.SmbsaHomeForm.action=sortAction;
	document.SmbsaHomeForm.target="_self";
	document.SmbsaHomeForm.submit();
	
}

//******************************************************************************
// Function Name		:	fnCreateSR
// Created Date			:	6-Jan-2005
// Description			:	Call service request action after setting passed parameters 
// Input Parameters		:	contractNum- The contract number for service request's contract number drop down ,
//							prodTechId- The device name for service request's product/technology drop down,
//							serialNum- Serial Number for service request's serial number drop down
//							deviceId-Device Id to be appended with the serial number 
// Output Parameters	:   None
//******************************************************************************
function fnCreateSR(contractNum, prodTechId, serialNum,deviceId)
{
	var windowName = new Date().getTime();
	
	var popUp = '';
	// Modified for synchronisation with Client and TSRT
	document.SmbsaHomeForm.contract_num.value=contractNum;	
	document.SmbsaHomeForm.selProdTechId.value=prodTechId;
	document.SmbsaHomeForm.serial_num.value=serialNum;
	document.SmbsaHomeForm.deviceId.value=deviceId;
	document.SmbsaHomeForm.serialNumDisplay.value=serialNum + " - " +deviceId;
	if(document.SmbsaHomeForm.selProdTechId.value=="")
	{
		document.SmbsaHomeForm.action="CreateSR.do";
		document.SmbsaHomeForm.srAction.value=var_Prod;
		document.SmbsaHomeForm.showConfirmPage.value=false;	
	}	
	else
	{	
	document.SmbsaHomeForm.showConfirmPage.value=true;
	document.SmbsaHomeForm.srAction.value=var_Next;
	document.SmbsaHomeForm.action="SubmitCreateSR.do";	
    }    
	popUp = window.open('' , windowName, var_SRWindowAttributes);
    document.SmbsaHomeForm.target = windowName;
    document.SmbsaHomeForm.submit();	
}

//******************************************************************************
// Function Name		:	fnSearchDevices
// Created Date			:	7-Jan-2005
// Description			:	call search action after validating search field
// Input Parameters		:	None
// Output Parameters	:   returns false if error is there
//******************************************************************************
function fnSearchDevices()
{
	var searchField=document.SearchForm.searchField.value;
	var searchString=document.SearchForm.searchString.value;
	//validate if user has entered the search string
	if(fnIsBlank(searchString.toString()))
		{	
			//If user has chosen contract 
			if(searchField==var_Contract)
				alert(alertBlankContract);
			//If user has chosen serialnumber	
			else if(searchField==var_SerialNum)
				alert(alertBlankSearchSerialNum);
			//If user has chosen product	
			else if(searchField==var_DeviceName)
				alert(alertBlankProductId);	
				
			document.SearchForm.searchString.focus();
			return false;
		}
	document.SearchForm.target="_self";
	document.SearchForm.action="MyDevices.do?deviceAction=SearchDevices";
	
}
//******************************************************************************
// Function Name		:	fnShowChildComponents
// Created Date			:	11-Jan-2005
// Description			:	Function that calls the action for showing child componenets
// Input Parameters		:	instanceId- Parent Instance Id,
//							serialNo-Parent serial number
// Output Parameters	:   None
//******************************************************************************
function fnShowChildComponents(instanceId,serialNo)
{
	document.SmbsaHomeForm.instanceId.value=instanceId;
	document.SmbsaHomeForm.serialNo.value=serialNo;
	document.SmbsaHomeForm.target="_self";
	document.SmbsaHomeForm.action="MyDevices.do?deviceAction=ChildDevices";
	document.SmbsaHomeForm.submit();
}

//******************************************************************************
// Function Name		:	fnContractDetails
// Created Date			:	11-Jan-2005
// Description			:	Function that calls the action for showing contract details
// Input Parameters		:	contractNo- Contract number whose details are to be shown
// Output Parameters	:   None
//******************************************************************************
function fnContractDetails(contractNo)
{
	document.SmbsaHomeForm.contractNo.value=contractNo;
	document.SmbsaHomeForm.target="_self";
	document.SmbsaHomeForm.action="MyDevices.do?deviceAction=ContractDetail";
	document.SmbsaHomeForm.submit();
}


//******************************************************************************
// Function Name		:	fnExcelDownload
// Created Date			:	13-July-2005
// Description			:	Function that sets the document type to Excel and calls the action MyDevices.do
// Input Parameters		:	deviceAction- Parameter to set the device action
// Output Parameters	:   None
//******************************************************************************
function fnExcelDownload(deviceAction)
{
	
	document.ExcelDownloadForm.docType.value=var_DocType;
	document.ExcelDownloadForm.deviceAction.value=deviceAction;
	document.ExcelDownloadForm.action="MyDevices.do";
	document.ExcelDownloadForm.submit();
}