var g_intervalHandle = new Array();
var g_tooltipVisible = new Array();
var g_tooltipText = new Array();

g_tooltipText["tooltipError"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Невалиден символ</b><br /><br />Въведени са невалидни символи, които ще бъдат игнорирани след изпращане не заявката. Придържайте се към използването единствено на букви от <b>английската азбука</b>, когато задавате име на град или държава.</p>';
g_tooltipText["tooltipSearch"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Как да търся?</b><br /><br />За да намерите телефонния код на дадена държава, моля въведете името на държавата на английски, например: United Kingdom. За да намерите телефонният код на населено място в дадена държава, моля въведете техните имена на английски, например: London, United Kingdom</p>';
g_tooltipText["tooltipTerms"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Кодове</b><br /><br />Посочете с мишката &nbsp;<img src="images/listing/question.gif" style="width:7px; height:7px;"/>&nbsp;&nbsp;за да разберете какво означава всяко от съкращенията.</p>';
g_tooltipText["tooltipCountryCode"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Какво е код на държава (КД)?</b><br /><br />Кодът на държава се използва за провеждане на международни телефонни разговори. Това е кодът на държавата, с която желаете да се свържете. Той винаги следва префикса за международно избиране на държавата, в която се намирате. За да проведете телефонен разговор от държава A с държава B, наберете:<br /><br />[ПМНИ на държава А] + [КД на държава B] + [КНМ] + [телефонен номер]</p>';
g_tooltipText["tooltipAreaCode"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Какво е код на населено място (КНМ)?</b><br /><br />Кодът на населено място се използва за провеждане на международни и междуградски разговори. За международни разговори наберете:<br /><br />[ПМНИ на държава А] + [КД на държава B] + [КНМ] + [телефонен номер]<br /><br />За междуградски разговори наберете:<br /><br />[ПМГИ] + [КНМ] + [телефонен номер]</p>';
g_tooltipText["tooltipIDD"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Какво е префикс за международно избиране (ПМНИ)?</b><br /><br />Префиксът за международно избиране се използва при провеждането на международни разговори и винаги предшества кода на държавата, с която се провежда телефонният разговор. За да проведете телефонен разговор от държава A с държава B, наберете:<br /><br />[ПМНИ на държава А] + [КД на държава B] + [КНМ] + [телефонен номер]</p>';
g_tooltipText["tooltipNDD"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Какво е префикс за междуградско изибиране (ПМГИ)?</b><br /><br />Префиксът за междуградско избиране се използва при провеждането на междуградски разговори и винаги предшества кода за населено място. За да проведете телефонен разговор от населено място A с населено място B, намиращи се в една и съща държава, наберете:<br /><br />[ПМГИ] + [КНМ] + [телефонен номер]</p>';

/*
g_tooltipText["tooltipError"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>Invalid character(s)</b><br /><br />You have entered an invalid character(s) that will be ignored after submitting your search query. Try to specify a location using only English alphabetical characters.</p>';
g_tooltipText["tooltipSearch"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>How to search?</b><br /><br />To find the country code for a specific country, please enter the country name. Example: United Kingdom. To find the code for a specific location in a country, please enter the location and the country name. Example: London, United Kingdom</p>';
g_tooltipText["tooltipTerms"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>What do country code, area code, IDD and NDD mean?</b><br /><br />Point with your mouse the question mark&nbsp;<img src="images/listing/question.gif" style="width:7px; height:7px;"/>&nbsp;&nbsp;icons to read what these terms mean.</p>';
g_tooltipText["tooltipCountryCode"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>What is a country code?</b><br /><br />The country code is used for international phone calls. With it you call to the listed country from the country you\'re in. The country code is preceded by the IDD of the country from which you call. The country code is followed by the area code of the location in the country to which you call.<br /><br />To call from country A to country B dial:<br /><br />[IDD prefix of country A] + [country code of country B] + [area code] + [phone number]</p>';
g_tooltipText["tooltipAreaCode"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>What is an area code?</b><br /><br />The area code is used for international and domestic calls. With it you call to the listed location within the specified country. It is followed by the phone number you need to call.<br /><br />For international calls dial:<br /><br />[IDD prefix of country A] + [country code of country B] + [area code] + [phone number]<br /><br />For domestic calls dial:<br /><br />[NDD prefix of country] + [area code] + [phone number]</p>';
g_tooltipText["tooltipIDD"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>What is IDD</b><br /><br />The IDD (International Direct Dial) prefix is used for international phone calls. With it you call from the country you\'re in to another one. It is followed by the country code of the country to which you call.<br /><br />To call from country A to country B dial:<br /><br />[IDD prefix of country A] + [country code of country B] + [area code] + [phone number]</p>';
g_tooltipText["tooltipNDD"] = '<p class="cTx fA11n" style="margin:10px; text-align:justify"><b>What is NDD</b><br /><br />The NDD (National Direct Dial) prefix is used for domestic phone calls. With it you call from one location to another within the same country. It is followed by the area code of the location to which you call.<br /><br />To call from location A to location B within one and the same country dial:<br /><br />[NDD prefix of the country] + [area code] + [phone number]</p>';
*/

function GetPosition(e) {
    if (e.offsetParent) {
        var c = GetPosition(e.offsetParent);
        return [e.offsetLeft + c[0], e.offsetTop + c[1]];
    } else {
        return [e.offsetLeft, e.offsetTop];
    }
}

function IsIE() {
   return (document.all ? true : false);
}

function ShowTooltipBelowElement(e, offsetx, offsety, w, h, id, s) {
    var ww = document.body.clientWidth - (IsIE() ? 10 : 32);
    var x = 0;
    var y = 0;

    c = GetPosition(e);
    c[0] += offsetx;
    c[1] += offsety;
  
    if ((c[0] + w) > ww) {
        x = c[0] - (c[0] + w - ww);
    } else {
        x = c[0];
    }
    y = c[1] + e.offsetHeight;
    
    ShowTooltipXY(x, y, w, h, id, s);
}




var g_z_index = 10;               // z-index variable that allows to show each new tooltip top most

function ShowTooltipXY(x, y, w, h, id, s) {
    e = document.getElementById(id);
    if (g_intervalHandle[id]) {
        clearInterval(g_intervalHandle[id]);
    }
    SetOpacity(e, 100);
    
    e.style.zIndex = g_z_index++;
    e.style.left = x;
    e.style.top = y;
    e.style.width = w;
    e.style.height = h;
    e.innerHTML = s;

    g_tooltipVisible[id] = true;
    e.style.visibility = 'visible';
    
    InitializeAnimation(e, x, y, w, h, s);
}




var g_c;                            // step counter
var g_e;                            // element
var g_t;                            // timer
var g_s;                            // string variable that temporarily contains the message of the tooltip
var g_x, g_y;                       // x and y start positions
var g_xs, g_ys                      // x and y step
var g_fx, g_fy, g_fw, g_fh;         // x, y, width, height final positions
var g_xsl, g_xsw, g_yst, g_ysh;     // x, y, width, height step positions
var g_zoom_steps = 10;              // number of steps
var g_zoom_delay = 15;              // delay between steps

function InitializeAnimation(e, x, y, w, h, s) {
    g_c = 0;
    g_e = e;
    g_s = s;
    g_fx = x;
    g_fy = y;
    g_fw = w;
    g_fh = h;
    g_x = x + w / 2;
    g_y = y + h / 2;
    g_xs = w / 2 / g_zoom_steps;
    g_ys = h / 2 / g_zoom_steps;        

    g_e.style.left = g_xsl = g_x;
    g_e.style.top = g_yst = g_y;
    g_e.style.width = g_xsw = 0;
    g_e.style.height = g_ysh = 0;

    e.innerHTML = '';
            
    AnimationTimer();
}

function AnimationTimer() {
    g_e.style.left = g_xsl = g_xsl - g_xs;
    g_e.style.width = g_xsw = g_xsw + g_xs * 2;
    g_e.style.top = g_yst = g_yst - g_ys;
    g_e.style.height = g_ysh = g_ysh + g_ys * 2;
        
    if (++g_c >= g_zoom_steps) {
        clearTimeout(g_t);
        g_e.style.left = g_fx;
        g_e.style.top = g_fy;
        g_e.style.width = g_fw;
        g_e.style.height = g_fh;
        g_e.innerHTML = g_s;
    } else {
        g_t = setTimeout("AnimationTimer()", g_zoom_delay);
    }
}




var g_fade_step = 3;
var g_fade_delay = 30;

function HideTooltip(id) {
    var e = document.getElementById(id);
    g_tooltipVisible[id] = false;
    g_intervalHandle[id] = setInterval('FadeOutTooltip("' + id + '", ' + g_fade_step + ')', g_fade_delay);
}

function FadeOutTooltip(id, s) {
    var e = document.getElementById(id);
    var o = GetOpacity(e);

    if (o - s > 0) {
       SetOpacity(e, o - s);
    } else {
        e.style.visibility = 'hidden';
    }
}

function SetOpacity(e, o) {
    if (IsIE()) {
        e.filters.alpha.opacity = o;
    } else {
        e.style.MozOpacity = o / 100;
    }
}

function GetOpacity(e) {
    return IsIE() ? e.filters.alpha.opacity : e.style.MozOpacity * 100;
}



var g_error = false;             // text validity flag

function CheckText(e) {
    var s = e.value;
    var l = s.length;
    var error = false;
    
    for (var i = 0; i < l; i++) {
        c = s.charCodeAt(i);
        if (c != 32 && c != 39 && c!= 44 && c != 45 && (c < 65 || c > 90) && (c < 97 || c > 122)) {
            error = true;
            break;
        }
    }
        
    if (!g_error && error) {
        g_error = true;
        ShowTooltipBelowElement(e, 100, -120, 440, 92, "tooltipError", g_tooltipText["tooltipError"]);
    } else if (g_error && !error) {
        g_error = false;
        HideTooltip("tooltipError");
    }
}