/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Revision : 
    =============================================*/
var cultureCode = "";
var PIA = null;

function getPIA()
{
/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Description:	responsible for creation of Proquest integration assistant object .
    =============================================*/
	try
	{
		if (!PIA || PIA == null)
		{
			PIA = new ActiveXObject("PQIntegrationAssistant3.PQPIA");
			
		}
	}
	catch(e)
	{
		//alert(e.description);
		PIA = null;
	}	
	
	return PIA;
}

function initPIA(name) {
/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Description:	this method calls the getPIA() to obtain a object of Proquest integration assistant. 
    It calls the PIA_InitializeSession() method of PIA to set the PIA object to use a particular session now 
    when we call some other method PIA the proprties of that particular session will be used..
    =============================================*/

  var status = false;
  getPIA();
  if (!PIA || PIA == null) {return status;}

  if (!cultureCode || cultureCode == null) {return status;}

  try {
    PIA.Set_PIA_Language(cultureCode);
    PIA.PIA_InitializeSession("EASy", name);
    status = true;
  }
  catch(e) {
    status = false;
    return e.message;
  }

  return status;
}


function sendToPIA(name, data) {
/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Description:	This method first set up a PIA object to use a particular session through initPIA() 
    then it loop through the data array and call the PIA_AddPart() method of PIA to send each part information 
    to PIA object. When all the parts are sent to PIA object then we call the PIA_ProcessParts() method of PIA 
    which will open the PIA screen and DMS to transfer parts from PIA to DMS.
    =============================================*/

  if (data == null || data <= 0) {return;}
  if (!name || name == null || name == "") {return;}
  
  
  if (!initPIA(name) || !PIA || PIA == null)
  {
  	return;
  }

	try
	{  
	  for (var i = 0; i < data.length; i++) {
			PIA.PIA_AddPart("EASy", data[i].PartNumber, data[i].Qty, data[i].PartName);
	  }
	
	  PIA.PIA_ProcessParts("EASy", name);
	}
	catch(e){}
}


function setupPIA(name) {
/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Description:	This function call the PIA method which will open the PIA Session Maintenance.
    =============================================*/

  
  var status = null;
  if (!name || name == null || name == "") {return status;}
  
  
  getPIA();

  if (!PIA || PIA == null)
  {
    
  	return;
  }

  if (!cultureCode || cultureCode == null) {return status;}

  try {
    PIA.Set_PIA_Language(cultureCode);
    status = PIA.PIA_SetupSession("EASy", name);
  }
  catch(e) {
    status = "PIA_SETUP_ERROR";
  }

  return status;
}



function getPIASession()
{
/* =============================================
    Author:		Tarun Kumar
    Create date: 8-April-2008
    Description:	this function call PIA method which will return all the session name configured on machine.
    =============================================*/

  getPIA();
  if (!PIA || PIA == null) {return status;} 
  return PIA.PIA_GetSessionNames("EASy");
}