var varxmlHTTP;
var mnAutoSaveMilliSeconds=0;
var mnAutoSaveMilliSecondsExp=0;
var mnAutoSaveInterval=3000;

var _hidFormLatestValue='';
function LoadXmlHTTP()
{
    if (window.XMLHttpRequest)
        {
        return new XMLHttpRequest();
        }
    if (window.ActiveXObject)
        {
        return new ActiveXObject("Microsoft.XMLHTTP");
        }
        return null;
}

function encodeTxt(pValue)
{
   var str = escape(pValue);
   str = str.replace(/\+/g,"%2B");
   str = str.replace(/%20/g,"+");
   return str;
}

function GetHelpData()
 {
 
 var URL = "AjaxEngine.aspx?Action=GetHelpData&ID="+arguments[0];
        varxmlHTTP=LoadXmlHTTP();
        if (varxmlHTTP == null)
            {
            alert("Your browser is not support for Ajax.");
            }
        varxmlHTTP.onreadystatechange=onGetHelpData;
        varxmlHTTP.open("GET",URL,true);
        varxmlHTTP.send(null);
 }
 
 function onGetHelpData()
 {
 if(varxmlHTTP.readyState == 4 && varxmlHTTP.status == 200)
    {
    var varValue = varxmlHTTP.responseText;
    document.getElementById("divHelp").innerHTML =varValue; 
    }
 } 

  function AutoSaveBeforeSubmit()
  {
        var dropdownIndex = document.getElementById('ddlCategory').selectedIndex;
        var URL = "AjaxEngine.aspx?Action=UpdateSecondForm&CategorytoPut="+document.getElementById('ddlCategory')[dropdownIndex].text+"&BreifDescInn="+encodeTxt(document.getElementById('BreifDescInnID').value)+"&origininnov="+encodeTxt(document.getElementById('OriginID').value)+"&Descinnov="+encodeTxt(document.getElementById('DescinnovId').value)+"&tecDescinnoID="+encodeTxt(document.getElementById('TscDescinnoID').value)+"&Performance="+encodeTxt(document.getElementById('PerformanceID').value);
         URL=URL+"&Commentofrele="+encodeTxt(document.getElementById('CommnetRepaID').value)+"&ApplicationOfutility="+encodeTxt(document.getElementById('ApplicationinnoID').value)+"&AdvantageofExt="+encodeTxt(document.getElementById('AdvExiTechID').value)+"&benifit="+encodeTxt(document.getElementById('BenInnovID').value)+"&timeStamp="+getTimeStamp();
        varxmlHTTP=LoadXmlHTTP();
        if (varxmlHTTP == null)
        {
            
        }        
        varxmlHTTP.onreadystatechange=onSaveSubmitSecondData;
        varxmlHTTP.open("GET",URL,true);
        varxmlHTTP.send(null);
     
  }
  
  function onSaveSubmitSecondData()
 {
     if(varxmlHTTP.readyState == 4 && varxmlHTTP.status == 200)
        {
            if(_hidFormLatestValue=="second")
                      AutoSaveSecondFormData();
        }
 }
  function AutoSaveThirdBeforeSubmit()
  {     

      var URL1 = "AjaxEngine.aspx?Action=UpdateThirdForm&WorkPresented="+encodeTxt(document.getElementById('WorkPreID').value)+"&Reason="+encodeTxt(document.getElementById('ReasonID').value)+"&timeStamp="+getTimeStamp();                
        varxmlHTTP=LoadXmlHTTP();
        if (varxmlHTTP == null)
        {
            //alert("Your browser is not support for Ajax.");
        }
        varxmlHTTP.onreadystatechange=onSaveSubmitThirdData;
        varxmlHTTP.open("GET",URL1,true);
        varxmlHTTP.send(null);     
  }
  
   function onSaveSubmitThirdData()
 {
     if(varxmlHTTP.readyState == 4 && varxmlHTTP.status == 200)
        {
        
            if(_hidFormLatestValue=="third")
                      AutoSaveThirdFormData();
        }
 }

    function AutoSaveSecondFormData()
    {
         setTimeout("AutoSaveBeforeSubmit();",3000);
    }

    function AutoSaveThirdFormData()
    {
    
         setTimeout("AutoSaveThirdBeforeSubmit();",3000);
    }
    function AutoSaveFormData()
    { 
        _hidFormLatestValue=arguments[0];
        if(_hidFormLatestValue=="second")
        {
            AutoSaveSecondFormData();
        }
        if(_hidFormLatestValue=="third")
        {
         
            AutoSaveThirdFormData();
        }
    }

function getTimeStamp()
{
    var currentTime = new Date();
    return currentTime.getFullYear() + "" + currentTime.getMonth() + "" + currentTime.getDate() + "" + currentTime.getHours() + "" + currentTime.getMinutes() + "" + currentTime.getSeconds() + "" + currentTime.getMilliseconds();
}

function CallAjaxForFirstStep()
{
      var URL1 = "AjaxEngine.aspx?Action=asdasd";                
      alert(URL1);
        varxmlHTTP=LoadXmlHTTP();
        if (varxmlHTTP == null)
        {
            //alert("Your browser is not support for Ajax.");
        }
        varxmlHTTP.onreadystatechange=CallAjaxForFirstStepAfter;
        varxmlHTTP.open("GET",URL1,true);
        varxmlHTTP.send(null);     

}
   function CallAjaxForFirstStepAfter()
 {
     if(varxmlHTTP.readyState == 4 && varxmlHTTP.status == 200)
        {
          ShowTabs('div2','SecondIDDIv');  
        }
 }
 
 function callHideDivFunction()
 {
       var URL1 = "AjaxEngine.aspx?Action=StartSession&timeStamp="+getTimeStamp();                
        varxmlHTTP=LoadXmlHTTP();
        if (varxmlHTTP == null)
        {
            //alert("Your browser is not support for Ajax.");
        }
        varxmlHTTP.onreadystatechange=callHideDivFunctionRea;
        varxmlHTTP.open("GET",URL1,true);
        varxmlHTTP.send(null);     

 }
 
  function callHideDivFunctionRea()
  {
    document.getElementById('darkBackgroundLayer').style.display = 'none';
    document.getElementById('NewPopupDiv').style.display = 'none';
  }
