var g_Lng = [
   { id:"ru", name:"Russian"},
   { id:"en", name:"English", is_default: true}
];

function GetLngIdFromPath() {
   var strLngId = null;

   for(var i = 0; i < g_Lng.length; i++){
      if(window.location.pathname.indexOf("/" + g_Lng[i].id + "/") == 0){  
         strLngId = g_Lng[i].id;
         break; 
      }
   }
   if(!strLngId){
      strLngId = GetLngIdDefault();
   }

   return strLngId;
}   


function GetLngIdDefault() {
   var strLngIdDefault = null;
   for(var i = 0; i < g_Lng.length; i++){
      if(g_Lng[i].is_default){ strLngIdDefault = g_Lng[i].id; break; }
   }
   return strLngIdDefault;
}   


function SetLng(strLngId){
   Cookie.write("lng", strLngId, { duration: 365 /* 1 year */, path: "/" });
}


function init() {
   if(!document.getElementById) {return false;}

   try {
      document.execCommand('BackgroundImageCache', false, true);
   } catch(e) {}


   var strCurLngId = GetLngIdFromPath();
   if(strCurLngId != Cookie.read('lng')){ SetLng(strCurLngId); }

   var strLngHtml = "";
   for(var i = 0; i < g_Lng.length; i++){
      if(strCurLngId == g_Lng[i].id){ continue; }
      if(strCurLngId == null && g_Lng[i].is_default){ continue; }
      var strHref = window.location.pathname;
      strHref = strHref.replace("/" + strCurLngId + "/", "/" + g_Lng[i].id + "/");

      strLngHtml += '<a id="lang-' + g_Lng[i].id + '" href="' + strHref + '">' + g_Lng[i].name + '</a>';
   }
   var lang_selector = $('lang-selector');
   lang_selector.set('html', strLngHtml);

   var strPage = document.getElementById("content").className;
   if(strPage == "page_main"){

   }
}



function PageContactsOnSubmit(){
   var bIsFormValid = true;

   var strName = document.frmInquiry.name.value;
   var warnNameEmpty = document.getElementById("warnNameEmpty");
   if(strName == ""){
      warnNameEmpty.style.display = "block";
      bIsFormValid = false;
   } else {
      warnNameEmpty.style.display = "none";
   }

   var strInquiry = document.frmInquiry.inquiry.value;
   var warnInquiryEmpty = document.getElementById("warnInquiryEmpty");
   if(strInquiry == ""){
      warnInquiryEmpty.style.display = "block";
      bIsFormValid = false;
   } else {
      warnInquiryEmpty.style.display = "none";
   }

   return bIsFormValid;
}

window.addEvent('domready', init);