function check_doc() {
    fmt = /(.jpg|.jpeg|.png|.gif|.pdf)$/i;
    return fmt.test(document.document_form.document.value);
}

function expandingWindow(anc, winwidth, winheight) {
  var imgwidth = winwidth;
  var imgheight = winheight;

  if (document.all) {
	var sizer = window.open("","fotowindow",'left=0,top=0,width='+winwidth+',height='+winheight+',scrollbars=no,fullscreen=yes,resizable=yes');
	sizer.document.write('<body bgcolor="#000000" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0"><table border="0" width="100%" height="100%"><tr><td width="100%" height="100%" valign="middle" align="center"><a href="javascript:return(false)" onClick="window.close()"><img src="' + anc.href + '" width="' + imgwidth + '" height="' + imgheight + '" border="0" alt="Back"><\/a><\/td><\/tr><\/table><\/body>');
  } else {
	document.write('<body bgcolor="#000000" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0"><table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr><td width="100%" height="100%" valign="middle" align="center"><a href="javascript:history.go(-1)"><img src="' + anc.href + '" width="' + imgwidth + '" height="' + imgheight + '" border="0" alt="Back"><\/a><\/td><\/tr><\/table><\/body>');
  }
}
						
function newDNSSubmit (dns_fill,msg) {
    allempty = 1;
    for (i=0; i<=dns_fill; i++) {
        el = document.getElementsByName("name_"+i)[0];
        if (el.value != "") {
            allempty = 0;
            break;
        }
        el = document.getElementsByName("ip_"+i)[0];
        if (el.value != "") {
            allempty = 0;
            break;
        }
    }
    if (allempty) {
		return confirm(msg);
    }else{
	    return true;
	}
}

function _check_all(Form, cBox, checked) {
	for (var i=0; i < Form.elements.length; i++){
	  if (Form.elements[i].name == cBox && Form.elements[i].disabled!=true) 
		Form.elements[i].checked = checked;}
}

function _uncheck_checker(Form, checker){
	if (Form[checker].checked==true) Form[checker].checked=false;
}

function switchableSelectBox(selectboxID, linksListParentID){
    var selectList = document.getElementById(selectboxID);
    var selectListItems = selectList.getElementsByTagName('option');
    var linkList = document.getElementById(linksListParentID).getElementsByTagName('a');
    for (i=0; i<linkList.length; i++) {
      if (linkList[i].id=='') {
       linkList[i].onclick = function() {
	for (j=0; j<selectListItems.length; j++) {
            if (this.firstChild.nodeValue == selectListItems[j].firstChild.nodeValue) {selectList.selectedIndex = selectListItems[j].index; selectList.style.outline="2px solid #f8981d"; setTimeout(function(){selectList.style.outline='none';}, 100); return false;}
        }
       }
      }
    }
}

function _is_any_checked(Form, cBox, Warning){

	for (var i=0; i < Form.elements.length; i++){
	if (Form.elements[i].name == cBox && Form.elements[i].checked == true ) {return true}
	}
	alert(Warning);
	return false;
}


function win_info(winname, url) {
var page_w = 800, page_h = 600;
if (window.screen) {
	page_w = window.screen.availWidth;
	page_h = window.screen.availHeight;
	page_w = (page_w < 800) ? 800 : page_w;
	page_h = (page_h < 600) ? 600 : page_h;
}

	var w = 600;
	var h = page_h * 0.7;
	var x = (page_w - w) * 0.5;
	var y = (page_h - h) * 0.5;
	var winProps = 'resizable=1,scrollbars=1';

	var args = 'width=' + w + ',height=' + h+ ',' + winProps
	+ ",screenX=" + x + ",screenY=" + y+ ",left=" + x + ",top=" + y;

	winhandle=window.open(url,winname,args);
	winhandle.focus();
	return false;
}

function win_document(for_link){

 var win_w = 800, win_h = 500;
 var x = 5, y = 10;

if (document.all) {
	y = window.screenTop - 40;
	x = window.screenLeft;
	win_h = document.body.clientHeight - 40;
	win_w = document.body.clientWidth*.8;
	if (win_w < 800) win_w = 800;
	x += (document.body.clientWidth - win_w) * .5; 
     }
     if (window.innerWidth) {
	y = window.screenY + 40;
	x = window.screenX + 4;
	win_h = window.innerHeight-40;
	win_w = window.innerWidth*.8;
	if (win_w < 800) win_w = 800;
	x += (window.innerWidth - win_w) * .5; 
     }

   var winProps = 'resizable=1,scrollbars=1,toolbar=1,status=1';

   var args = 'width=' + win_w + ',height=' + win_h+ ',' + winProps +
              ',screenx=' + x + ',screeny=' + y+ ',left=' + x + ',top=' + y;

   newwinhandle=window.open(for_link.href,for_link.target,args);
   newwinhandle.focus();
   return false;
}

function openwindow() {

  var x = screen.width - 50;
  var y = screen.height - 50;
  var min_x = 600;
  var min_y = 420;
  x = (x > min_x) ? x : min_x;
  y = (y > min_y) ? y : min_y;

  xleft = screen.width/2 - x/2;	
  ytop  = screen.height/2 - y/2;
  xleft = (xleft > 50) ? xleft : 50;
  ytop  = (ytop  > 50) ? ytop  : 50;

  window.open('', 'new', 
 'top=ytop,left=xleft,width=x,height=y,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes,location=yes,directories=yes,status=yes');
  window.blur('new');
}


function FieldEmpty(field, WMessg) {

	if (field.type == 'text' || field.type == 'textarea')
		value = field.value;
	else
		value = field.options[field.selectedIndex].value;

	if (value == "" || value == 0 ) {
		alert(WMessg);
		field.focus();
		return false;
	} else {
		return true;
	}
}

function paging(start_from){              
                                          
 if (document.forms.list_paging){         
        with (document.forms.list_paging){
                start.value = start_from; 
                submit();                 
                return false;             
                                          
        }                                 
 }else{                                   
                return true;              
 }                                        
}                                         

function BackTo(page_back){

	if (page_back){
		history.go(-page_back);
		return false;
	}
	return true;
}



/*
Скрипт, изменяющий теги title и alt
*/


window.onerror = null;

tooltip = {
attr_name: "tooltip",
blank_text: "",
newline_entity: "   ",
max_width:0,
delay: 300,


t: document.createElement("DIV"),
c: null,
g: false,

m: function(e){
if (tooltip.g){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];

if (!e) e = window.event;

if (e.pageX || e.pageY) {
    x = e.pageX;
    y = e.pageY;
} else if (e.clientX || e.clientY) {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
}

tooltip.a(x, y);
}
},

d: function(){
tooltip.t.setAttribute("id", "tooltip");
document.body.appendChild(tooltip.t);
a = document.all ? document.all : document.getElementsByTagName("*");
aLength = a.length;
for (var i = 0; i < aLength; i++){

if (!a[i]) continue;
tooltip_title = a[i].getAttribute("title");
if (tooltip_title && typeof tooltip_title != "string") tooltip_title = "";

tooltip_alt = a[i].getAttribute("alt");
tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip.blank_text;
if (tooltip_title || tooltip_blank){
a[i].setAttribute(tooltip.attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip.blank_text : tooltip.blank_text) : tooltip_title);
if (a[i].getAttribute(tooltip.attr_name)){
a[i].removeAttribute("title");
if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}else if (tooltip_alt && a[i].complete){
a[i].setAttribute(tooltip.attr_name, tooltip_alt);
if (a[i].getAttribute(tooltip.attr_name)){
a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}
if (!a[i].getAttribute(tooltip.attr_name) && tooltip_blank){
}
}
document.onmousemove = tooltip.m;
window.onscroll = tooltip.h;
tooltip.a(-99, -99);
},

s: function(e){
d = window.event ? window.event.srcElement : e.target;
if (!d.getAttribute(tooltip.attr_name) && !d.parentNode.getAttribute(tooltip.attr_name) ) return;
s = d.getAttribute(tooltip.attr_name) || d.parentNode.getAttribute(tooltip.attr_name);
if (tooltip.newline_entity){
s = s.replace(/\&/g,"&amp;");
s = s.replace(/\</g,"&lt;");
s = s.replace(/\>/g,"&gt;");
s = s.replace(eval("/" + tooltip.newline_entity + "/g"), "<br />");
tooltip.t.innerHTML = s;
}else{
if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
tooltip.t.appendChild(document.createTextNode(s));
}
tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", tooltip.delay);
tooltip.g = true;
},

h: function(e){
tooltip.t.style.visibility = "hidden";
if (!tooltip.newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
clearTimeout(tooltip.c);
tooltip.g = false;
tooltip.a(-99, -99);
},

l: function(o, e, a){
if (o.addEventListener) o.addEventListener(e, a, false);
else if (o.attachEvent) o.attachEvent("on" + e, a);
else return null;
},

a: function(x, y){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
)[0];

if( window.innerHeight && window.scrollMaxY ) {
    w_width = document.body.clientWidth + window.scrollMaxX;
    w_height = window.innerHeight + window.scrollMaxY;
} else if( document.body.scrollHeight > document.body.offsetHeight ) {
    w_width = document.body.scrollWidth;
    w_height = document.body.scrollHeight;
} else {
    w_width = document.body.offsetWidth + document.body.offsetLeft;
    w_height = document.body.offsetHeight + document.body.offsetTop;
}

//w_width = oCanvas.clientWidth ? oCanvas.clientWidth + oCanvas.scrollLeft : window.innerWidth + window.pageXOffset;
//w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop; // should be vice verca since Opera 7 is crazy!

tooltip.t.style.width = ((tooltip.max_width) && (tooltip.t.offsetWidth > tooltip.max_width)) ? tooltip.max_width + "px" : "auto";

t_width = tooltip.t.offsetWidth;
t_height = tooltip.t.offsetHeight;

tooltip.t.style.left = x + 8 + "px";
tooltip.t.style.top = y + 8 + "px";

if (x + t_width > w_width) tooltip.t.style.left = w_width - t_width + "px";
if (y + t_height > w_height) tooltip.t.style.top = w_height - t_height + "px";
}
}

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
if (root.addEventListener) root.addEventListener("load", tooltip.d, false);
else if (root.attachEvent) root.attachEvent("onload", tooltip.d);
}


//functions to work with className
//******************
function addClass (ele,cls) {
    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function hasClass (ele,cls) {
    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function removeClass (ele,cls) {
    if (hasClass(ele,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        ele.className=ele.className.replace(reg,' ');
    }
}
//****************
//function for faq-list
//*****************
function FaqList(listId,ansId) {
    var _self = this;
    this.listId = listId;
    this.ansId = ansId;
    this.ansLink = document.getElementById(this.ansId);
    this.listLink = document.getElementById(this.listId);
    this.ansLink.style.display = 'none';
    addClass(this.listLink,'underline');
    var tmp = document.getElementById(this.listId).getElementsByTagName('A');
    this.qCount=tmp.length;
    this.qArr = new Array(this.qCount);
    this.savedHash = 0;
    for(var i = 0; i<this.qCount; i++) {
        var el = tmp[i];
        var id = el.hash;
        el.onclick = function(event){_self.showAns(event)};
        id = id.substr(1,id.length);
        this.qArr[id] = {
            show: false,
            appended: false,
            elem: el.parentNode,
            ans: null
        }
    }
    //_self.savedHash = window.location.hash;
    if(window.location.hash.length>0) {
        this.savedHash = window.location.hash;
        this.showAns(this.savedHash);
    }
    var br = navigator.userAgent.toLowerCase();
    if(br.indexOf('msie 7.0')!=-1||br.indexOf('msie 6.0')!=-1) {
        var tmp = this.listLink.getElementsByTagName('OL');
        for (var i=0; i<tmp.length; i++) {
            var t = tmp[i];
            autoNumLi(t);
        }
    }
}
FaqList.prototype.showAns = function(event) {
		var e;
		var id;
		if(typeof arguments[0] == 'string') 
    	id = arguments[0];
		else {
			e = event || window.event;
			var src = e.target || e.srcElement;
			id = src.hash;
		}		
    id = id.substr(1,id.length);
    if(!this.qArr[id].appended) {
        this.qArr[id].appended = true;
        var h2 = document.getElementById(id);
        var ansBlock = h2.nextSibling;
        if(ansBlock.nodeType != 1) {
            ansBlock = ansBlock.nextSibling;
        }
        var html = ansBlock.cloneNode(true);
        this.qArr[id].ans = this.qArr[id].elem.appendChild(html);
        this.ansLink.removeChild(ansBlock);
        this.ansLink.removeChild(h2);
    }
    if(!this.qArr[id].show) {
        this.qArr[id].show = true;
        addClass(this.qArr[id].elem,'on');
        if(this.savedHash!=0) {
            this.qArr[id].elem.scrollIntoView();
            this.savedHash = 0;
            var scrolled = document.documentElement.scrollTop;
            var needScroll = this.qArr[id].elem.offsetTop+150;
            if(scrolled < needScroll) {
                var toScroll = needScroll - scrolled;
                setTimeout(function(){window.scrollBy(0,toScroll);},500);
            }
        }
    } else {
        this.qArr[id].show = false;
        removeClass(this.qArr[id].elem,'on');
    }
		window.location.replace('#'+id);
		return false;
}
function autoNumLi(elem) {
    elem.style.listStyleType = 'none';
    var count = elem.childNodes.length;
    var pLI = elem.parentNode;
    var pOL = pLI.parentNode;
    var section = 0;
    while (pOL.childNodes[section]!=pLI) {
        section++;
    }
    for ( var subsection = 0; subsection < count; subsection++ ) {
        var eLI = elem.childNodes[subsection];
        var tmp = document.createElement('SPAN');
        tmp.className = 'sub-num';
        tmp.innerHTML = (section + 1) + '. ' + (subsection + 1)+'. ';
        eLI.insertBefore(tmp,eLI.firstChild);
    }
}


function resetForm(elem,exception) {
		//elem - this
		//exception - array[string1,string2...] || string				
		if (elem != undefined && elem != null && elem.nodeType == 1) {
			while (elem.tagName.toLowerCase()!='form') elem = elem.parentNode; 
			var t, tag, type, inEx, name, pattern;
			if (typeof exception == 'string') pattern = exception.replace('*','[.]*');
			for (var i = 0; i < elem.elements.length; i++) {
				t = elem.elements[i];
				if (t != undefined && t.nodeType == 1) {
					inEx = false;				
					tag = t.tagName.toLowerCase();
					type = t.type;
					name = t.name.toLowerCase();
					if (exception != undefined && exception != null && exception.length > 0) {
						if (typeof exception == 'object') {
							for (var j = 0; j < exception.length; j++) {
								pattern = exception[j].replace('*','[.]*');
								if (name == pattern || (name.match(new RegExp(pattern)) && pattern != exception[j])) {
									inEx = true;
									break;
								}
							}
						} else if (typeof exception == 'string') {
							if (name == pattern || (name.match(new RegExp(pattern)) && pattern != exception)) inEx = true;
						}
					}
					if (!inEx) {
						if (type == 'text' || tag == 'textarea' || type=='password') t.value = '';
						else if (type == 'select-one' || type == 'select-multy') t.selectedIndex = 0;
						else if (type == 'radio' || type == 'checkbox') t.checked = false;
					}
				}
			}
		}
		return false;
	}
