﻿var laststr = "";
var str;
var lang = "";
var isMainPage = 0;
str = new String;
var act="/order/?s=1000&domains=";
var action = new Array();
var tm = setTimeout("",600000);
$(document.domainf).keypress(function (e) {
	  if(e.which == 13 && document.domainf.domains.value == "") { return false; }
});

$(document.domainf).keyup(function (e) {
	  clearTimeout(tm);  tm = setTimeout("check();",1000);	  
});

var n = 0;
var domain = "";
var ext = "";

$("#uls").hide();

function openDomain() {
$('#domaincheckresult').mousedown(function(){
return false;
	});
$('body').one('mousedown',hideDomain);
}

function hideDomain(){
if (document.getElementById('domaincheckresult').style.display=='block')
document.getElementById('domaincheckresult').style.display='none';
}

function check()
{
$("#trButMore").hide();
$("#trBut").show();
if (isMainPage == 1) openDomain();

      if(document.domainf.domain.value != laststr)
      {
      str = document.domainf.domain.value;
      if(str.length >= 2)
      {
      	go(document.domainf.domain.value);
      }
      else
      {
	$("#domaincheckresult").fadeOut("slow");
	$("#out, #uls").hide();
	$("#entxt").show();
	document.domainf.domains.value = "";
      }
      laststr = document.domainf.domain.value;
      }
}

function go(params)
{
document.domainf.domains.value = "";
//$("#domainf").attr({action: 'http://store.activecloud.ru/index.php?NAME_PATH=DOMAIN&SCREEN=DOMAINSEXTENSION_SCREEN'});
$("#entxt").hide();
action = new Array();
var dot = false;
domain = "";
ext = "";
var post = "";
append_checking();
n=0;
for(var i=0;i<_domains.length;i++)
{
$("#" + _domains[i]).empty().append(_domains[i].replace(/_/, "."));       
}
for (var i = 0; i < document.domainf.domain.value.length; i++) {
   if(document.domainf.domain.value.charAt(i) == '.') {dot = true; break;}
else {domain += document.domainf.domain.value.charAt(i);}
}
if(dot)
{
$("#domaincheckresult").removeClass("posDomainPop2");
$("#domaincheckresult").addClass("posDomainPop");
$("#domaincheckresult").fadeIn("slow");
for(i++; i<document.domainf.domain.value.length;i++)
{
ext += document.domainf.domain.value.charAt(i);
}
$.post('/domains/',{domain: params, rand: (Math.random()*Math.random()), ext: ext},show_who);
}
else
{
$("#domaincheckresult").hide();
$("#domaincheckresult").removeClass("posDomainPop2");
$("#domaincheckresult").addClass("posDomainPop");
$("#domaincheckresult").fadeIn("slow");
$("#uls").show();
$("#whois").hide();
$("#check, #map").show();
$("#out2, #out").empty();
$("#domaincheckresult").find("li").removeClass().addClass("gray");
for(i=0;i<_domains.length;i++)
{
post += "$.post('/domains/index.php',{domain: params, rand: (Math.random()*Math.random()), ext: '" + _domains[i].replace("_", ".") + "'},function(data){var tmp;tmp = transform(data);show(tmp,'" + "#" + _domains[i] + "');});"; 
}
eval(post);
}
}

function show_who(data)
{
if(isMainPage == 1) {$("#out").hide();} else {$("#out").show();}
$("#uls").hide();
$("#out2").empty();
var tmp;
tmp = transform(data);
switch(tmp)
{
case 4:
if(lang != "by"){
$("#out2").append("<p><b>" + document.domainf.domain.value+ "</b> <font color=#B93C10>занят</font></p>");
}
else
{
$("#out2").append("<p><b>" + document.domainf.domain.value+ "</b> <font color=#B93C10>заняты</font></p>");
}
$("#domainf").attr({action: '/' + lang + '/services/domains/'});
document.domainf.domains.value = document.domainf.domain.value;
$("#check, #map").hide();
if(isMainPage == 1) $("#whois").show();
$("#out").append(data);
break;

case 3:
if(lang != "by") {$("#out2").append("<p><b>" + document.domainf.domain.value + "</b> <font color=#6fb012>свободен</font></p>");}
else {
$("#out2").append("<p><b>" + document.domainf.domain.value + "</b> <font color=#6fb012>свабодны</font></p>");}
$("#map, #whois").hide();
$("#check").show();
document.domainf.domains.value = document.domainf.domain.value;
break;

default:
$("#check, #map, #whois").hide();
if(isMainPage == 1) {$("#out").show();}
}

append_result();
$("#out").append(data);
}


function transform(data)
{
			var ln;
			var tmp;
			var complete;
			var str;
			complete = new String;
			str = new String;
			str = data;
			ln = str.length;
			complete = str.substring(ln-2,ln);
			if(complete == "-1")
			{
			tmp = parseInt(complete);
			}
			else {
			complete = str.charAt(ln-1);
			tmp = parseInt(complete);
			}
			return tmp;
}

function show(tmp,domen)
{
var PlanID;
switch(tmp)
{

case 1:
n++;
$(domen).removeClass();
$(domen).addClass("green");
var html = domen.substr(1);
if(lang == "ru"){
var matches = {
'by' :  'PlanID[1689]',
'com' :  'PlanID[1690]',
'org' :  'PlanID[1691]',
'net' :  'PlanID[1692]',
'ru' :  'PlanID[1693]',
'name' :  'PlanID[1694]',
'info' :  'PlanID[1695]',
'bz' :  'PlanID[1696]',
'biz' :  'PlanID[1697]',
'tel' :  'PlanID[1698]',
'mobi' :  'PlanID[1699]',
'me' :  'PlanID[1700]',
'tv' :  'PlanID[1701]',
'cc' :  'PlanID[1702]',
'ws' :  'PlanID[1703]',
'aero' :  'PlanID[1704]',
'asia' :  'PlanID[1705]',
'at' :  'PlanID[1706]',
'be' :  'PlanID[1707]',
'ca' :  'PlanID[1708]',
'ch' :  'PlanID[1709]',
'cn' :  'PlanID[1710]',
'de' :  'PlanID[1711]',
'dk' :  'PlanID[1712]',
'es' :  'PlanID[1713]',
'fr' :  'PlanID[1714]',
'in' :  'PlanID[1715]',
'it' :  'PlanID[1716]',
'kz' :  'PlanID[1717]',
'li' :  'PlanID[1718]',
'mx' :  'PlanID[1719]',
'nl' :  'PlanID[1720]',
'su' :  'PlanID[1721]',
'tj' :  'PlanID[1722]',
'tw' :  'PlanID[1723]',
'uk' :  'PlanID[1724]',
'uz' :  'PlanID[1725]',
'us' :  'PlanID[1726]'
};
}
if(lang == "by" || lang == "ru-by"){
var matches = {
'by' :  'PlanID[481]',
'com' :  'PlanID[482]',
'org' :  'PlanID[483]',
'net' :  'PlanID[484]',
'ru' :  'PlanID[485]',
'name' :  'PlanID[486]',
'info' :  'PlanID[487]',
'bz' :  'PlanID[488]',
'biz' :  'PlanID[489]',
'tel' :  'PlanID[490]',
'mobi' :  'PlanID[491]',
'me' :  'PlanID[492]',
'tv' :  'PlanID[493]',
'cc' :  'PlanID[494]',
'ws' :  'PlanID[495]',
'aero' :  'PlanID[496]',
'asia' :  'PlanID[497]',
'at' :  'PlanID[498]',
'be' :  'PlanID[499]',
'ca' :  'PlanID[501]',
'ch' :  'PlanID[502]',
'cn' :  'PlanID[503]',
'de' :  'PlanID[504]',
'dk' :  'PlanID[505]',
'es' :  'PlanID[506]',
'fr' :  'PlanID[507]',
'in' :  'PlanID[508]',
'it' :  'PlanID[509]',
'kz' :  'PlanID[510]',
'li' :  'PlanID[511]',
'mx' :  'PlanID[512]',
'nl' :  'PlanID[513]',
'su' :  'PlanID[514]',
'tj' :  'PlanID[515]',
'tw' :  'PlanID[516]',
'uk' :  'PlanID[517]',
'uz' :  'PlanID[518]',
'us' :  'PlanID[519]'
};
}

if(lang == "az" || lang == "ru-az"){
var matches = {
'by' :  'PlanID[2604]',
'com' :  'PlanID[2605]',
'org' :  'PlanID[2606]',
'net' :  'PlanID[2607]',
'ru' :  'PlanID[2608]',
'name' :  'PlanID[2609]',
'info' :  'PlanID[2610]',
'bz' :  'PlanID[2611]',
'biz' :  'PlanID[2612]',
'tel' :  'PlanID[2613]',
'mobi' :  'PlanID[2614]',
'me' :  'PlanID[2615]',
'tv' :  'PlanID[2616]',
'cc' :  'PlanID[2617]',
'ws' :  'PlanID[2618]',
'aero' :  'PlanID[2619]',
'asia' :  'PlanID[2620]',
'at' :  'PlanID[2621]',
'be' :  'PlanID[2622]',
'ca' :  'PlanID[2623]',
'ch' :  'PlanID[2624]',
'cn' :  'PlanID[2625]',
'de' :  'PlanID[2626]',
'dk' :  'PlanID[2627]',
'es' :  'PlanID[2628]',
'fr' :  'PlanID[2629]',
'in' :  'PlanID[2630]',
'it' :  'PlanID[2631]',
'kz' :  'PlanID[2632]',
'li' :  'PlanID[2633]',
'mx' :  'PlanID[2634]',
'nl' :  'PlanID[2635]',
'su' :  'PlanID[2636]',
'tj' :  'PlanID[2637]',
'tw' :  'PlanID[2638]',
'uk' :  'PlanID[2639]',
'uz' :  'PlanID[2640]',
'us' :  'PlanID[2641]',
'eu' :  'PlanID[2642]'
};
}

if(lang == "ge" || lang == "ru-ge"){
var matches = {
'by' :  'PlanID[2190]',
'com' :  'PlanID[2191]',
'org' :  'PlanID[2192]',
'net' :  'PlanID[2193]',
'ru' :  'PlanID[2194]',
'name' :  'PlanID[2195]',
'info' :  'PlanID[2196]',
'bz' :  'PlanID[2197]',
'biz' :  'PlanID[2198]',
'tel' :  'PlanID[2199]',
'mobi' :  'PlanID[2200]',
'me' :  'PlanID[2201]',
'tv' :  'PlanID[2202]',
'cc' :  'PlanID[2203]',
'ws' :  'PlanID[2204]',
'aero' :  'PlanID[2205]',
'asia' :  'PlanID[2206]',
'at' :  'PlanID[2207]',
'be' :  'PlanID[2208]',
'ca' :  'PlanID[2209]',
'ch' :  'PlanID[2210]',
'cn' :  'PlanID[2211]',
'de' :  'PlanID[2212]',
'es' :  'PlanID[2214]',
'fr' :  'PlanID[2215]',
'in' :  'PlanID[2216]',
'it' :  'PlanID[2217]',
'kz' :  'PlanID[2218]',
'li' :  'PlanID[2219]',
'mx' :  'PlanID[2220]',
'nl' :  'PlanID[2221]',
'su' :  'PlanID[2222]',
'tj' :  'PlanID[2223]',
'tw' :  'PlanID[2224]',
'uk' :  'PlanID[2225]',
'uz' :  'PlanID[2226]',
'us' :  'PlanID[2227]',
'eu' :  'PlanID[2228]'
};
}

if(lang == "am" || lang == "ru-am"){
var matches = {
'by' :  'PlanID[2491]',
'com' :  'PlanID[2492]',
'org' :  'PlanID[2493]',
'net' :  'PlanID[2494]',
'ru' :  'PlanID[2495]',
'name' :  'PlanID[2496]',
'info' :  'PlanID[2497]',
'bz' :  'PlanID[2498]',
'biz' :  'PlanID[2499]',
'tel' :  'PlanID[2500]',
'mobi' :  'PlanID[2501]',
'me' :  'PlanID[2502]',
'tv' :  'PlanID[2503]',
'cc' :  'PlanID[2504]',
'ws' :  'PlanID[2505]',
'aero' :  'PlanID[2506]',
'asia' :  'PlanID[2507]',
'at' :  'PlanID[2508]',
'be' :  'PlanID[2509]',
'ca' :  'PlanID[2510]',
'ch' :  'PlanID[2511]',
'cn' :  'PlanID[2512]',
'de' :  'PlanID[2513]',
'dk' :  'PlanID[2514]',
'es' :  'PlanID[2515]',
'fr' :  'PlanID[2516]',
'in' :  'PlanID[2517]',
'it' :  'PlanID[2518]',
'kz' :  'PlanID[2519]',
'li' :  'PlanID[2520]',
'mx' :  'PlanID[2521]',
'nl' :  'PlanID[2522]',
'su' :  'PlanID[2523]',
'tj' :  'PlanID[2524]',
'tw' :  'PlanID[2525]',
'uk' :  'PlanID[2526]',
'uz' :  'PlanID[2527]',
'us' :  'PlanID[2528]',
'eu' :  'PlanID[2529]'
};
}

html = html.replace(/_/, ".");

PlanID = matches[html];



$(domen).empty().append("<label><input id=n" + n + " type=checkbox value=" + html + " name='"+ PlanID +"' >" + html + "</label>");

$(domen).find("input").click(function () {
var fullname=document.domainf.domain.value + "." + html; 
fullname = fullname.replace(/_/, "."); // changing '_' to '.'
if(inArray(action,fullname)==false)
{
action.push(fullname);
}
else
{
delElement(action,fullname);
}
act=action.join("_");
document.domainf.domains.value = act;
$("#domain").focus();
});

break;

case 0:
n++;
$(domen).removeClass();
$(domen).addClass("red");
$(domen).click(function () {});
whois_ajax(domen);
break;
case -1:
n++;            
break;
default:
n++;
break;
}

if(n==_domains.length) {append_result();}
}

function inArray(array,str)
{
for(var i=0; i<array.length; i++)
{
if(array[i]==str)
{
return 1;
}
}
return 0;
}

function delElement(array,str)
{
for(var i=0; i<array.length; i++)
{
if(array[i]==str)
{
array.splice(i,1);
}
}
return 0;
}

function whois_ajax(domen)
{
var html = domen.substr(1);
html = html.replace(/_/, ".");
if(isMainPage == 1)
{
$(domen).empty().append("<a href=" + "/" + lang + "/services/domains/?domain=" + document.domainf.domain.value +"." + html  +  ">" + html + "</a>");
}
else
{
$(domen).empty().append("<a href='#'>" + html + "</a>");
$(domen).click(function () {
$.post('/domains/',{domain: document.domainf.domain.value+'.'+html, rand: (Math.random()*Math.random()), ext: html},show_who); 
append_checking();
return false;
});
}
}

function append_checking()
{
if(lang != "by"){
if(isMainPage == 1) $('#top').empty().append('<img src="/images/domain_load.gif" style="margin-right: 6px;" valign="middle" /><b>Идет проверка...&nbsp;&nbsp;&nbsp;</b>'); 
else $('#top').empty().append('<h2>Идет проверка...&nbsp;&nbsp;&nbsp;<img src="/images/i_run.gif" style="margin-right: 6px;" valign="middle" /></h2>');
}
else {
if(isMainPage == 1) $('#top').empty().append('<img src="/images/domain_load.gif" style="margin-right: 6px;" valign="middle" /><b>Ідзе праверка...&nbsp;&nbsp;&nbsp;</b>'); 
else $('#top').empty().append('<h2>Ідзе праверка...&nbsp;&nbsp;&nbsp;<img src="/images/i_run.gif" style="margin-right: 6px;" valign="middle" /></h2>');
}
}

function append_result()
{
if(lang != "by") {
if(isMainPage == 1) $('#top').empty().append("<b>Результаты проверки:</b>");
else $('#top').empty().append("<h2>Результаты проверки:</h2>");
} else { 
if(isMainPage == 1) $('#top').empty().append("<b>Вынікі праверкі:</b>"); 
else $('#top').empty().append("<h2>Вынікі праверкі:</h2>");
}
}
