var working = false;
var C=function(){
	var s=document.getElementById('login_pass');
	if(s) if(s.value) clean(s);
}
setInterval(C,100);

function get_http(){
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new
                ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
        xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function rate(Id, Raiting){
  document.getElementById("FaqRate").innerHTML="<div style=\"padding-top:4px;\"><b>Спасибо за ответ.</b><div>";
  if(!this.http){
    this.http = get_http();
    working = false;
  }

  if (!working && this.http) {
    var http = this.http;
    url = "/faq/rate/?id="+Id+"&raiting="+Raiting;
    this.http.open("GET", url, true);
    this.http.onreadystatechange = function() {
      if (http.readyState == 4) {
        working = false;
      }
    }
    working = true;
    this.http.send(null);
  }
}

function clean(a)
{
	var p=a.previousSibling;
	if(p)
	{
		p.style.top="-9999px";
		a.onblur=function()
		{
			if(!a.value)
			{
				p.style.top=""
			}
		};
	}
}

function Popup_show()
{
    document.getElementById('PopupContainer').style.display = 'block';
}

function Popup_hide()
{
    document.getElementById('PopupContainer').style.display = 'none';
    document.cookie="selectlanguage=no; path=/; expires=Mon, 01-Jan-2012 00:00:00 GMT";
}

/* замена фона селекта*/
document.write('<style type="text/css">select.styled { position: relative; width: 95px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
var Custom = {
	init: function() {

		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
			  var url=window.location.href;
    		if(document.getElementById("select" + this.name).childNodes[0].nodeValue!="English"){
    			  //parent.location="http://beta.smsdeluxe.net/";
    			  url=url.replace("ru","net");
				}else{
				    //parent.location="http://beta.smsdeluxe.ru/";
				    url=url.replace("net","ru");
				}
				parent.location=url;
				
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

function selectShortNumber(select){
window.location='/'+document.getElementById('t_number').options[document.getElementById('t_number').selectedIndex].value+'/';
}
