﻿// This function calls the Web Service method.  
function ajaxRequest(el)
{
    // client side javascript
    if (el != "reset")
    {
        updateGrid(el);
    }
    else
    {
        resetGrid();
    }
    // access webmethod
    PageMethods.UpdateProducts(el, onSuccess, onFailure);
}

// callback functions that
function onSuccess(result, count, userContext, methodName)
{
    var ret = document.getElementById("ctl00_ContentPlaceHolder1_products");
    ret.innerHTML = result;
    var num = document.getElementById("count").value;
    var number = document.getElementById("ctl00_ContentPlaceHolder1_number");
    number.innerHTML = num;
}

function onFailure(error, userContext, methodName)
{
    if(error !== null) 
    {
        var ret = document.getElementById("ctl00_ContentPlaceHolder1_products");
        ret.innerHTML = "An error occurred: " + error.get_message();
    }
}

function resetGrid()
{
	
    var col = "";
    var temp = "";
    var visited;
    
    col = "bat";
    for(i = 0; i < 4; i++){
	    temp = "ctl00_ContentPlaceHolder1_" + col + i;
	    visited = document.getElementById(temp);
	    if (i == 0)
	    {
	        // turn on the selected element
	        // visited.setAttribute('className', 'selon');
	        setAttribute(visited, 'selon');
	    }
	    else
	    {
	        // else off
	        // visited.setAttribute('className', 'seloff');
	        setAttribute(visited, 'seloff');
	    }
    }
    
    col = "chg";
    for(i = 0; i < 4; i++){
	    temp = "ctl00_ContentPlaceHolder1_" + col + i;
	    visited = document.getElementById(temp);
	    if (i == 0)
	    {
	        // turn on the selected element
	        // visited.setAttribute('className', 'selon');
	        setAttribute(visited, 'selon');
	    }
	    else
	    {
	        // else off
	        // visited.setAttribute('className', 'seloff');
	        setAttribute(visited, 'seloff');
	    }
    }
    
    col = "pwr";
    for(i = 0; i < 3; i++){
	    temp = "ctl00_ContentPlaceHolder1_" + col + i;
	    visited = document.getElementById(temp);
	    if (i == 0)
	    {
	        // turn on the selected element
	        // visited.setAttribute('className', 'selon');
	        setAttribute(visited, 'selon');
	    }
	    else
	    {
	        // else off
	        // visited.setAttribute('className', 'seloff');
	        setAttribute(visited, 'seloff');
	    }
    }
    

}

function updateGrid(el)
{
	
	var len = el.length - 1;
    var col = left(el, len);
    var temp = "";
    var visited;
    var count = 4;
    if (col == "ctl00_ContentPlaceHolder1_pwr") count = 3;
    
    // loop through column controls
    for(i = 0; i < count; i++){
	    temp = col + i;
	    visited = document.getElementById(temp);
	    if (visited.id == el)
	    {
	        // turn on the selected element
	        // visited.setAttribute('className', 'selon');
	        setAttribute(visited, 'selon');
	    }
	    else
	    {
	        // else off
	        // visited.setAttribute('className', 'seloff');
	        setAttribute(visited, 'seloff');
	    }
    }

}


function left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function setAttribute(el, cls)
{
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        el.setAttribute('className', cls);
    }
    else
    {
        el.setAttribute('class', cls);
    }

}


if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

// popup related

function showOverlay()
{
	document.getElementById("overlay-text").style.display="block";
	document.getElementById("overlay-box").style.display="block";
}
function hideOverlay()
{
	document.getElementById("overlay-text").style.display="none";
	document.getElementById("overlay-box").style.display="none";
}


  
  


