﻿// JScript File
setTimeout("Sys.Application.add_load(AppLoad)",100);
var postBackElement;
var loadingdd=false;

function AppLoad()
{
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
}

function BeginRequest(sender, args) 
{
    postBackElement = args.get_postBackElement();

    if (postBackElement.id != 'ctl00_ContentPlaceHolder1_tmr_1') {
        document.getElementById("FetchingProductsDiv").style.display = "block";
        document.getElementById("ProductsDisplayDiv").style.display = "none";
    }
} 

function EndRequest(sender, args) 
{
	//loadingdd=false;
  // Check to see if there's an error on this request.
  if (args.get_error() != undefined)
  {
    // If there is, show the custom error.
    //window.location.reload( true );

    // Let the framework know that the error is handled, 
    //  so it doesn't throw the JavaScript alert.
   // args.set_errorHandled(true);
  }

    if (postBackElement.id != 'ctl00_ContentPlaceHolder1_tmr_1') {
        document.getElementById("FetchingProductsDiv").style.display = "none";
        document.getElementById("ProductsDisplayDiv").style.display = "block";
    }  
}

function loadDD(clientid, attribute, searchid, z_refresh)
{
	var a=document.getElementById(clientid);
	if(attribute!="#"){
		resetDD(a, "Loading...", true)
		PageMethods.GetDropdownValues(clientid,	attribute, searchid, z_refresh, OnSucceeded, OnFailed);
	}
	else{
		a.disabled=true;
	}
}
function OnSucceeded(result, userContext, methodName) 
{
	var a=document.getElementById(result[0][0]);
	for(i=1;i<result.length;i++)
	{
		a.options[i-1] = new Option(result[i][1], result[i][0]);
	}
	a.disabled=false;
}


function addCriteria(dd, clientid, attribute, searchid)
{
	PageMethods.AddCriteria(clientid, attribute, searchid, dd.value, AddOK, OnFailed);
	//setTimeout("loadDropdowns()","200");
}

function AddOK(result, userContext, methodName)
{
	ShowSearchResults();
	setTimeout("loadDropdowns()","200");
}


	// Callback function invoked on failure 
	// of the page method.
function OnFailed(error, userContext, methodName) 
{
	if(error !== null) 
	{
		//alert("An error occurred: " + error.get_message());
        $get('divErrorMessage').style.visibility = "visible";
	}
}

function CloseError() {
  // Hide the error div.
  $get('divErrorMessage').style.visibility = "hidden";
}

function resetDD(dd, message, disabled)
{
	dd.options.length=1
	dd.options[0].text=message;
	dd.disabled=disabled;
}


