﻿function Apply(){__doPostBack('LINK','');}
var displayElement;
var gloabali = 0;
// Initializes global variables and session state.
function pageLoad()
{
    displayElement = $get("MS");
    //alert(displayElement);
    
    for(i = 0 ; i< array1.length;i++)
    {
        GetCheckResult(array1[i][0],i, OnSucceeded, OnFailed);
    }            
}

// Gets the session state value.
function GetCheckResult(rawId,i) 
{
    PageMethods.GetResult(rawId, i, OnSucceeded, OnFailed);
}

function OK(rawId,i) 
{  
    PageMethods.OkClick(rawId,i, OnSucceededOk, OnFailed);
}

function CancelClick(rawId) 
{ 
    PageMethods.CancelClick(rawId, OnCancel, OnFailed);   
}
function OnCancel(result,userContext, methodName) 
{
    Reload();   
   // Sys.WebForms.PageRequestManager.getInstance()._doPostBack('AA','')
}
////Sets the session state value.
//function SetSessionValue(key, value) 
//{
//    PageMethods.SetSessionValue(key, value, 
//        OnSucceeded, OnFailed);
//}

    function Reload()
    {
     __doPostBack('AA','');
    }

function OnSucceededOk(result,userContext, methodName) 
{
    Reload();   
    //Sys.WebForms.PageRequestManager.getInstance()._doPostBack('AA','')

//    values = result.split('|');    
//    price = values[0];
//   // alert(result);    
//    localI = values[1];
//    $get(array1[localI][1]).innerHTML = '';  
//    $get(array1[localI][2]).innerHTML = '';  
//    $get(array1[localI][3]).innerHTML = '';  
//    displayElement = $get(array1[values[1]][4]);  
//     displayElement.className = 'p';  
//    displayElement.innerHTML = price + '€';
}

// Callback function invoked on successful 
// completion of the page method.

function OnSucceeded(result, userContext, methodName) 
{
   var localI;

    values = result.split('|');
    var RawId = values[0];
    var status  = values[1];
    localI = values[3];
    
    var nextDiv = $get("next");
  //  alert(status);
   // alert(localI);
    //['43','ctl00_C_R3_ctl00_div1','ctl00_C_R3_ctl00_tdRes']
    if(status == 1 || status == 2 || status == 3)
    { 
    
        nextDiv.style.display = "none";
    
        displayElement = $get(array1[localI][2]);        
        displayElement.className = 'err'; 
        displayElement.innerHTML = values[2];   
        
        if(status == 1)
        { // Is possible To Change only Period           
        
            displayElement.innerHTML = values[2];    
                               
        }
        if(status == 2)
        {
        // Is possible To Change bannerType
        
           displayElement = $get(array1[localI][4]);        
//         displayElement.className = 'err';   
           displayElement.innerHTML = '<a style="cursor:pointer"  onclick = OK('+RawId+','+localI+')>Уменьшить</a>';
        }
        
        if(status == 3)
        {
          // Is possible To Change Percent
 
            
            displayElement = $get(array1[localI][5]);        
            displayElement.innerHTML = '<a style="cursor:pointer"  onclick = OK('+RawId+','+localI+')>Уменьшить %</a>';    
        
        }
        
         displayElement = $get(array1[localI][1]); 
         displayElement.className = 'tar mn'; 
         
       // displayElement.innerHTML = '<IMG SRC=../images/btn/ok1.gif style="cursor:pointer" onclick = OK('+RawId+','+localI+') />' +'<br>' + '<IMG SRC=../images/btn/cancel1.gif style="cursor:pointer" onclick=CancelClick('+RawId+') />';               
    }
//    if(status == 4)
//    {     
    
        displayElement1 = $get(array1[localI][1]);        
        displayElement1.className = 'tar mn';   
    
        displayElement = $get(array1[localI][3]);        
        //displayElement.className = 'tar mn';
        displayElement.innerHTML = '<span class=\"it1\">' + values[4] + '</span>' + '<b> lei</b> ';
    //}  
  

}

// Callback function invoked on failure 
// of the page method.
function OnFailed(error, userContext, methodName) 
{
    if(error !== null) 
    {
        displayElement.innerHTML = "An error occurred: " + 
            error.get_message();
    }
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

