﻿
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 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;
        }
    }
}


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 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 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 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  );
               //alert("wwc -120:" + newCookie+"flasObj:" +oFlash);                                       
               oFlash.WriteCoockie(newCookie );                  
           }
           else
           {
              //alert("wwc -124:" + newCookie);                                       
              oFlash.WriteCoockie(';;;;;;lang=' + language + ';;' ); 
           }
        }
    }
    catch (ex) {} 
}


$(document).ready(function() {
   
    $(".ddlLang").change(function() {});

    try {
            //removed on 03.03.2011 CreateFlashCookie(); [writing languge to flash cookie]
        }
    catch (e) { }

});



