//============================================================================
//                           BEGIN CLASS DEFINITION
//============================================================================
//                                                                          
//  Name:           AjaxAccess                  
//                                                                          
//  Description:    The purpose of this class is to encapsulate the required
//                  functionality to asynchronously retrieved data on the
//                  client using AJAX. It contains a private method,
//                  this.LoadXmlDoc to interract with the web server as well
//                  as other public methods to perform specific functions
//                  used by the application.
//
//  Methods:        AjaxAccess();
//                  LoadXmlDoc();
//                  LoadXmlDocAsync();
//                  IsValidUserNameAndPassword(username, password);
//
//                                            
//============================================================================


//============================================================================

var AjaxAccess_CallBack  = new Object();

//============================================================================
//                                                                          
//  Name:           AjaxAccess
//                                                                          
//  Scope:          Class AjaxAccess
//
//  Description:    This is the constructor for the AjaxAccess class. 
//                                       
//  Parameters:     none
//                                                                          
//============================================================================
function AjaxAccess(applicationName)
{
   this.applicationName = applicationName;
   
   
   this.LoadXmlDoc                          = Ajax_LoadXmlDoc;
   this.LoadXmlDocAsync                     = Ajax_LoadXmlDocAsync;
   this.GetApplicationName                  = Ajax_GetApplicationName;
   this.GetApplicationNameUrl               = Ajax_GetApplicationNameUrl;
   this.LogoutSession                       = Ajax_LogoutSession;
   this.IsSessionRegistered                 = Ajax_IsSessionRegistered;
   this.IsValidUserNameAndPassword          = Ajax_IsValidUserNameAndPassword;   
   this.IsUserAdmin                         = Ajax_IsUserAdmin;
   this.GetSessionUsername                  = Ajax_GetSessionUsername;
   this.GetSessionPassword                  = Ajax_GetSessionPassword;
   this.GetAllAssets                        = Ajax_GetAllAssets;
   this.UpdateSnNum                         = Ajax_UpdateSnNum;
   this.UpdateModel                         = Ajax_UpdateModel;
   this.UpdateServiceTag                    = Ajax_UpdateServiceTag;
   this.UpdateSimId                         = Ajax_UpdateSimId;
   this.UpdateImeiId                        = Ajax_UpdateImeiId;
   this.UpdatePhoneNum                      = Ajax_UpdatePhoneNum;
   this.UpdateUnitId                        = Ajax_UpdateUnitId;
   this.UpdateAssetId                       = Ajax_UpdateAssetId;
   this.UpdateAssetScanCode                 = Ajax_UpdateAssetScanCode;
   this.UpdateSite                          = Ajax_UpdateSite;
   this.UpdateVendor                        = Ajax_UpdateVendor;
   this.UpdateLocation                      = Ajax_UpdateLocation;
   this.UpdateUserId                        = Ajax_UpdateUserId;
   this.UpdateDriverId                      = Ajax_UpdateDriverId;
   this.UpdateRouteId                       = Ajax_UpdateRouteId;
   this.UpdateStatus                        = Ajax_UpdateStatus;
   this.UpdateSpecs                         = Ajax_UpdateSpecs;
   this.GetLocationsBySite                  = Ajax_GetLocationsBySite;
   this.GetAssetsBySerialNumber             = Ajax_GetAssetsBySerialNumber;
   this.GetAssetsByUnitId                   = Ajax_GetAssetsByUnitId;
   this.GetAssetsByAssetId                  = Ajax_GetAssetsByAssetId;
   this.GetAssetsBySite                     = Ajax_GetAssetsBySite;
   this.GetAssetsByLocation                 = Ajax_GetAssetsByLocation;
   this.GetAssetsByStatus                   = Ajax_GetAssetsByStatus;
   this.GetAssetsBySiteAndStatus            = Ajax_GetAssetsBySiteAndStatus;
   this.GetAssetsByLocationAndStatus        = Ajax_GetAssetsByLocationAndStatus;
   this.GetAssetsByVendor                   = Ajax_GetAssetsByVendor;
   this.GetAssetsByAssetType                = Ajax_GetAssetsByAssetType;
   
   
   return this;
}
//============================================================================
//
//Name:          this.LoadXmlDoc
//
//Scope:          Class AjaxAccess
//
//Description:    This method loads xml document and to interract with 
//the web server. 
//
//Parameters:     url      - a string containing web address
//
//formData - a string containing html method 
//051
//============================================================================
function Ajax_LoadXmlDoc(url, formData)
{   
	
	var formAction  = formData ? "POST" : "GET";
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var xmlHttp     = window.XMLHttpRequest ? new XMLHttpRequest()  :
						new ActiveXObject("Microsoft.XMLHTTP");   
 
	xmlHttp.open(formAction, url, false);
	xmlHttp.setRequestHeader("Content-Type", contentType);
	xmlHttp.send(formData);

	
	return xmlHttp.responseText;
}
//============================================================================
//
//Name:          this.LoadXmlDoc
//
//Scope:          Class AjaxAccess
//
//Description:    This method loads xml document and to interract with 
//the web server. 
//
//Parameters:     url      - a string containing web address
//
//formData - a string containing html method 
//
//============================================================================
function Ajax_LoadXmlDocAsync(url, formData, callBack)
{  
	var formAction  = formData ? "POST" : "GET";
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var xmlHttp     = window.XMLHttpRequest ?
	new XMLHttpRequest()  :
	new ActiveXObject("Microsoft.XMLHTTP");   
	
	
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
		callBack(xmlHttp.responseText);
		}
	};    

	xmlHttp.open(formAction, url, true);
	xmlHttp.setRequestHeader("Content-Type", contentType);
	xmlHttp.send(formData);
}


//============================================================================
//
//Name:           Ajax_GetApplicationName
//
//Scope:          Class AjaxAccess
//
//Description:    This method returns application name to the file.
//
//Parameters:     none
//                                
//============================================================================
function Ajax_GetApplicationName()
{  
	if(this.applicationName == null)
	   { 
	      var url         = (window.location.href.toUpperCase()).replace("HTTP://", "");
	      var slash1Index = url.indexOf("/");
	      var slash2Index = (url.slice(slash1Index + 1)).indexOf("/");
	      var appName     = url.substr((slash1Index + 1), slash2Index);
	   
	      return appName;
	   }
	   else
	   {
	      return this.applicationName;
	   }
}



//============================================================================
//                                                                        
//Name:           this.GetApplicationNameUrl
//                                                                        
//Scope:          Class AjaxAccess
//
//Description:    This method returns application name url to the file.
//                                     
//Parameters:     none
//                                                                       
//============================================================================
function Ajax_GetApplicationNameUrl()
{
	//return "/" + this.GetApplicationName() + "/"; //local version
	return this.GetApplicationName() + "/"; //internet version
	
	
}

function Ajax_LogoutSession()
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/LogoutSession.php";
	var formData     = "";
	var response     = this.LoadXmlDoc(url, formData);
	
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	} 
}
//============================================================================
//
//Name:           Ajax_IsSessionRegistered
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user's name and password are 
//valid or not. 
//
//============================================================================
function Ajax_IsSessionRegistered()
{ 
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/IsSessionRegistered.php";
	var formData     = "";
	var response     = this.LoadXmlDoc(url, formData);
	
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_IsValidUserNameAndPassword
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user's name and password are 
//valid or not. 
//
//Parameters:     username - a string containing user's name
//
//password - a string containing user's password
//
//============================================================================
function Ajax_IsValidUserNameAndPassword(username, password)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/IsValidUsernameAndPassword.php";
	var formData     = "username=" + escape(username) + "&password=" +
						escape(password);
	var response     = this.LoadXmlDoc(url, formData);
	
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
	
}


//============================================================================
//
//Name:           Ajax_IsUserAdmin
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user is admin or not.
//
//============================================================================
function Ajax_IsUserAdmin(username)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/IsUserAdmin.php";
	var formData     = "username=" + escape(username) ;
	
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_GetSessionUsername
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user is admin or not.
//
//============================================================================
function Ajax_GetSessionUsername()
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetSessionUsername.php";
	var formData     = "";
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return response.substring(8);      
	}   
}

function Ajax_GetLocationsBySite(site)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetLocationsBySite.php";
	var formData     = "site=" + escape(site);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 	
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		 
		return eval(response.substring(8));      
	}   
}

function Ajax_GetSessionPassword()
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetSessionPassword.php";
	var formData     = "";
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
 
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return response.substring(8);      
	}   
}
//============================================================================
//
//Name:           Ajax_GetAllAssets
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user's name and password are 
//valid or not. 
//
//Parameters:      
//
//
//
//============================================================================
function Ajax_GetAllAssets()
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAllAssets.php";
	var response     = this.LoadXmlDoc(url);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");
	 
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
}

function Ajax_GetAssetsBySerialNumber(serialNumber)
{
 
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsBySerialNumber.php";
	var formData     = "serialNumber=" + escape(serialNumber);
	var response     = this.LoadXmlDoc(url, formData);

 
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
}

function Ajax_GetAssetsByUnitId(unitId)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByUnitId.php";
	var formData     = "unitId=" + escape(unitId);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
}

function Ajax_GetAssetsByAssetId(assetId)
{
	
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByAssetId.php";
	var formData     = "assetId=" + escape(assetId);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
}

function Ajax_GetAssetsBySite(site)
{

	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsBySite.php";
	var formData     = "site=" + escape(site);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
	
}

function Ajax_GetAssetsByLocation(location)
{
 
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByLocation.php";
	var formData     = "location=" + escape(location);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    } 
	
}
function Ajax_GetAssetsByVendor(vendor)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByVendor.php";
	var formData     = "vendor=" + escape(vendor);
	var response     = this.LoadXmlDoc(url, formData);
		
 
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    }
}

function Ajax_GetAssetsByAssetType(assetType)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByAssetType.php";
	var formData     = "assetType=" + escape(assetType);
	var response     = this.LoadXmlDoc(url, formData);
		
 
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    }
	
}


function Ajax_GetAssetsByStatus(status)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByStatus.php";
	var formData     = "status=" + escape(status);
	var response     = this.LoadXmlDoc(url, formData);
		
 
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    }
}

function Ajax_GetAssetsBySiteAndStatus(site, status)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsBySiteAndStatus.php";
	var formData     = "site=" + escape(site) + "status=" + escape(status);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    }
}

function Ajax_GetAssetsByLocationAndStatus(location, status)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/GetAssetsByLocationAndStatus.php";
	var formData     = "location=" + escape(location) + "status=" + escape(status);
	var response     = this.LoadXmlDoc(url, formData);
		
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " ");
	response = response.replace(/&quot;/g, '"');
	response = response.replace(/\n/g, "\\n");
    response = response.replace(/\r/g, "\\r");

	if(response.substring(0, 6).toUpperCase() == "ERROR:")
    {
       var message = response.substring(6, 80);
       throw new Error(message);
    }
    else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
    {  
	   var message = unescape(response).substring(0, 40);  
       throw new Error(message);
    }
    else
    {
    	return response.substring(8);
    }
}




//============================================================================
//
//Name:           Ajax_UpdateSnNum
//
//Scope:          Class AjaxAccess
//
//Description:    This method checks whether user's name and password are 
//valid or not. 
//
//Parameters:     number - a string that contains asset's serial number
//              id       - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateSnNum(number, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateSnNum.php";
	var formData     = "number=" + escape(number) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   

	
}

//============================================================================
//
//Name:           Ajax_UpdateModel
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new model number with asset id
//
//Parameters:     model   - a string that contains asset's model number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateModel(model, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateModel.php";
	var formData     = "model=" + escape(model) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   

	
}

//============================================================================
//
//Name:           Ajax_UpdateServiceTag
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new model number with asset id
//
//Parameters:     model   - a string that contains asset's model number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateServiceTag(tag, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateServiceTag.php";
	var formData     = "tag=" + escape(tag) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   

	
}

//============================================================================
//
//Name:           Ajax_UpdateSimId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new model number with asset id
//
//Parameters:     model   - a string that contains asset's model number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateSimId(sim, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateSimId.php";
	var formData     = "sim=" + escape(sim) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}
//============================================================================
//
//Name:           Ajax_UpdateImeiId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new model number with asset id
//
//Parameters:     model   - a string that contains asset's model number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateImeiId(imei, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateImeiId.php";
	var formData     = "imei=" + escape(imei) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}
//============================================================================
//
//Name:           Ajax_UpdatePhoneNum
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new model number with asset id
//
//Parameters:     model   - a string that contains asset's model number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdatePhoneNum(phone, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdatePhoneNum.php";
	var formData     = "phone=" + escape(phone) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateUnitId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new unit id  number with asset id
//
//Parameters:     unit   - a string that contains asset's unit id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateUnitId(unit, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateUnitId.php";
	var formData     = "unit=" + escape(unit) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}
//============================================================================
//
//Name:           Ajax_UpdateAssetId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateAssetId(asset, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateAssetId.php";
	var formData     = "asset=" + escape(asset) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}
//============================================================================
//
//Name:           Ajax_UpdateAssetScanCode
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateAssetScanCode(asset_scan_code, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateAssetScanCode.php";
	var formData     = "asset_scan_code=" + escape(asset_scan_code) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateSite
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateSite(site, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateSite.php";
	var formData     = "site=" + escape(site) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}


function Ajax_UpdateVendor(vendor,id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateVendor.php";
	var formData     = "vendor=" + escape(vendor) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}


//============================================================================
//
//Name:           Ajax_UpdateLocation
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateLocation(location, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateLocation.php";
	var formData     = "location=" + escape(location) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateUserId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateUserId(user_id, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateUserId.php";
	var formData     = "user_id=" + escape(user_id) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateDriverId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateDriverId(driver_id, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateDriverId.php";
	var formData     = "driver_id=" + escape(driver_id) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateRouteId
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateRouteId(route_id, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateRouteId.php";
	var formData     = "route_id=" + escape(route_id) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateStatus
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateStatus(status, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateStatus.php";
	var formData     = "status=" + escape(status) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}

//============================================================================
//
//Name:           Ajax_UpdateSpecs
//
//Scope:          Class AjaxAccess
//
//Description:    This method updates new asset id  number with id
//
//Parameters:     asset   - a string that contains asset's asset id number
//              id      - a integer that contains asset id
//
//password - a string containing user's password
//
//============================================================================
function Ajax_UpdateSpecs(specs, id)
{
	var preAppendStr = this.GetApplicationNameUrl();
	var url          = preAppendStr + "Ajax/UpdateSpecs.php";
	var formData     = "specs=" + escape(specs) + "&id=" +
						escape(id);
	var response     = this.LoadXmlDoc(url, formData);
	
	response = response.replace(/^\s*/, "").replace(/\s*$/, ""); 
	response = response.replace(/\s{2,}/, " "); 
	
	if(response.substring(0, 6).toUpperCase() == "ERROR:")
	{
		var message = response.substring(6, 80);

		throw new Error(message);
	}
	else if(response.substring(0, 7).toUpperCase() != "SUCCESS")
	{
		var message = unescape(response).substring(0, 40);

		throw new Error(message);
	}
	else
	{
		return eval(response.substring(8));      
	}   
}



//============================================================================
//                                                                        
//Name:           constructQueryString
//                                                                        
//Scope:          Class AjaxAccess
//
//Description:    Th method constructs the querystring for
//                AddNewFeatureVersion. 
//                                     
//Parameters:     newFeature - an instance of Feature object
//
//                username   - a string containing user name
//
//                domain     - a string containing user domain
//                                                                        
//============================================================================
function constructQueryString(newFeature, username, domain)
{
 var queryString = "name=" + escape(newFeature.GetName()) + 
                   "&number=" + escape(newFeature.GetNumber()) + 
                   "&description=" + escape(newFeature.GetDescription()) +
                   "&Experimental=" + escape(newFeature.Experimental()) +
                   "&featureType=" + newFeature.GetType().GetNumber() +
                   "&parameters=" + escape(newFeature.GetParameterCount()) +
                   "&username=" + escape(username) +
                   "&domain=" + escape(domain);


 for(var i = 0; i < newFeature.GetParameterCount(); i++)
 {
    var parameterName        = escape(newFeature.parameters[i].GetName());
    var parameterType        = newFeature.parameters[i].GetType().GetNumber();
    var parameterNumber      = newFeature.parameters[i].GetNumber();
    var parameterSize        = newFeature.parameters[i].GetSize();
    var parameterDesc        = escape(newFeature.parameters[i].GetDescription());
    var parameterEncrypted = newFeature.parameters[i].Encrypted().toString().toLowerCase();
    var enumerations         = newFeature.parameters[i].GetEnumerations();
    var enumerationCount     = (parameterType == FeatureParameterType.Enumeration) ? enumerations.length : 0;
    
    
    queryString += "&parameterName_" + i + "=" + parameterName;
    queryString += "&parameterType_" + i + "=" + parameterType;
    queryString += "&parameterNumber_" + i + "=" + parameterNumber;
    queryString += "&parameterSize_" + i + "=" + parameterSize;
    queryString += "&parameterDescription_" + i + "=" + parameterDesc;
    queryString += "&parameterEncrypted_" + i + "=" + parameterEncrypted;
    queryString += "&enumerationCount_" + i + "=" + enumerationCount;
    
    for(var j = 0; j < enumerationCount; j++)
    {
       queryString += "&enumerationName_" + i + "_" + j + "=" + escape(enumerations[j].GetName());
       queryString += "&enumerationValue_" + i + "_" + j + "=" + escape(enumerations[j].GetValue());
    }
 }

 return queryString;                              
}









