﻿
function jsleep(s){
	s;
	var a=true;
	var n=new Date();
	var w;
	var sMS=n.getTime();
	while(a){
		w=new Date();
		wMS=w.getTime();
		if(wMS-sMS>s) a=false;
	}
}
 
function readFlashCookie()
{ 

    var lang;
    try
    {
       var myCookie = oFlash.ReadCoockie() ;
    }
    catch (ex)
    {
        setTimeout(readFlashCookie, 100);
        return;
    }
    
    var pageToBack =  "" ; 
          
    if (window.location.search.indexOf ("back=") > 0 )
    {
      pageToBack = window.location.search.substring(6);
    }
    else
    {
      pageToBack = window.location ; 
    }
    
    if (typeof(myCookie) != undefined && myCookie != null)
    {
        try
        {
           //debugger;
           var indx = myCookie.indexOf('lang=' ) ;
            
           //get language from flashcookie
           lang = myCookie.substring(indx + 5 ,indx + 7) ;
           CreateRegCookie (lang); 
           window.location = pageToBack ;
         }
        
        catch(ex){ }
    }
    
    if (myCookie==null)
    {
        window.location = pageToBack;
    }        
}           

function  IsRegCookieFound()
{
  var result ; 
  $.ajax({
              type: "GET",
              url:  "CookieCreator.aspx",
              cache: false,
              async: false,
              data: {
                      "action" : "GetCookieLang"                                        
                    },          
              success: function(res)
              {
                result = res ;
              },
              error: function (XMLHttpRequest, textStatus, errorThrown) 
              {            
                res = false;
              }
           }); 
    
    if (result==null || result=='undefined' || result=="")
    {    
        return false ;
    }
    else
    {
        return true ;
    }                    
}

function CreateFlashCookie()
{  

    try
    {   var language = $(".ddlLang").val() ;
      
        if (language!=null && language!=undefined && language!="")
        { 
        
           var currentCookie;
          
           try
            {
               currentCookie = oFlash.ReadCoockie() ;               
            }
            catch (ex)
            {   
                setTimeout(CreateFlashCookie, 100);
                return;
            }
           
           if ( currentCookie!=null && currentCookie!=undefined)
           {                                       
               var indx = currentCookie.indexOf('lang=' ) ;               
               var oldLang = currentCookie.substring(indx + 5 ,indx + 7) ;                                               
               var newCookie = currentCookie.replace (oldLang ,language  );
                                      
               oFlash.WriteCoockie(newCookie );                  
           }
           else
           {
              oFlash.WriteCoockie(';;;;;;lang=' + language + ';;' ); 
           }
        }
    }
    catch (ex) {} 
}

function CreateRegCookie(lang)
{ 
    if (lang!=null && lang!='undefined' && lang!="")    
    {
  
       $.ajax({
                  type: "GET",
                  url:  "CookieCreator.aspx",
                  cache: false,
                  async: false,
                  data: {
                          "action" : "SetCookieLang" ,                   
                          "lang" : lang
                        },          
                  success: function(res)
                  {},
                  error: function (XMLHttpRequest, textStatus, errorThrown) 
                  {            
                    res = false;
                  }
               });    
     }
    
}

function querySt(ji) 
{
   var hu ="" ; 
   if (window.location.search.indexOf ("back=") > 0)
   {

     hu = window.location.search.substring(6);
   
   }
   else
   {
      hu = window.location ;          
   }
    
    gy = hu.split("&");
    for (i=0;i<gy.length;i++)
    {
        var res ; 
       
        ft = gy[i].split("=");
        if (ft[0] == ji)
        {
            if (ft[1]==null || ft[1]=='undefined')
            {
                res='' ; 
            }
            else
            {
                res = ft[1] ;
            }
            
            return res ;
        }
    }
}

$(document).ready(function()
{
  $(".ddlLang").change(function()
  { 
     //$("#inpGa").val("0");    
     //alert("header:" +  $("#inpGa").val() )    ;
     
     //if opera needed extar refresh
     if (navigator.userAgent.indexOf('Opera') !=  -1)
     {
        top.location.href = top.location.href ;
     }
   }); 

   try
   {   
       CreateFlashCookie();          
   }
   catch(e){}   
   
});


