/*function openurl(){
	var url = document.selectNav.gotourl.options[document.selectNav.gotourl.selectedIndex].value;
    if ( url && url != '#' ) {
        eval("document.location='"+url+"'");
    }
}*/
 function getClass(name,type) {
        var r = [];
        var re = new RegExp("(^| )" + name + "( |$)");

        var e = document.getElementsByTagName(type || "*");
        for ( var i = 0, len = e.length; i < len; i++ )
                if ( re.test(e[i].className) ) r.push( e[i] );
        return r;
 }


	function calculateWidth() {
		maxWidth=665;
		bodyWidth = window.document.body.offsetWidth
		leftWidth = Math.round( bodyWidth * 0.37);
		leftFloat = getClass('left-float','div');
		rightFloat = getClass('right-float','div');
		if (leftWidth > maxWidth) {
			for (i=0; i<leftFloat.length; i++) {
				leftFloat[i].style.width= maxWidth + 'px';
			}
			for (i=0; i<rightFloat.length; i++) {
				rightFloat[i].style.marginLeft=maxWidth + 'px';
			}
		} else {
			for (i=0; i<leftFloat.length; i++) {
				leftFloat[i].style.width= '37%';
			}
			for (i=0; i<rightFloat.length; i++) {
				rightFloat[i].style.marginLeft= '37%';
			}
		}
//		alert('maxWidth=' + maxWidth + '; bodyWidth=' + bodyWidth + '; leftWidth=' + leftWidth + '; leftFloat.length=' + leftFloat.length + '; rightFloat.length=' + rightFloat.length)
	}



function showHide(id)
{
    obj = $('div#' + id)[0];
    if (obj.style.display == 'block')  {
        $('div#' + id).hide('fast')
    } else {
        $('div#' + id).show('fast')
    }
    return true;
}

function show(id)
{
    obj = $('div#' + id)[0];
    if (obj.style.display != 'block')  {
        $('div#' + id).show('fast')
    }
}

function viewFile(fileName, id, section_id)
{
    //alert([id,section_id]);
    var obj = document.getElementById('link_' + id);
    obj.className = 'active';
    if (currentDocument != 1) {
        currentDocument.className = '';
    }
    currentDocument = obj;
    show(section_id);
    var iframe = document.getElementById('page');
    iframe.src = fileName;
}


function popupUrl(name, uri, wdt, hgt) {
var posCode = '';
var ie = (document.all)? true : false;
var nn6 = (!ie && document.getElementById)? true : false;
var nn4 = (document.layers)? true : false;
if (nn4 || nn6 || ie) {
if ( (screen.height < 481) && (hgt > 400) ) { hgt = 400 }
	posX = Math.round((screen.width - wdt) / 2);
	posY = Math.round((screen.height - hgt) / 2);
	posCode = (nn4 || nn6)? ",screenX="+posX+",screenY="+posY : ",left="+posX+",top="+posY;
}
popupedWin = window.open(uri, name, "status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=no,location=no,width="+wdt+",height="+hgt+posCode);
popupedWin.focus();
}


function popupWindow(fileUrl, winW, winH, winN, scrollB) {
	var winWidth = winW;
	var winHeight = winH;
	var winName = (winN)? winN : 'popupWin'
	var scrollBars = (scrollB)? scrollB : 'auto'
	/*if (nn4 || ie4 || dom) {
		if (screen.width < winWidth + 50) { winWidth = screen.width - 50; scrollbars = 'yes' }
		if (screen.height < winHeight + 100) { winHeight = screen.height - 100; scrollbars = 'yes' }
		posX = Math.round((screen.width - winWidth) / 2);
		posY = Math.round((screen.height - winHeight) / 2);
		posCode = (nn4 || dom)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
	} else {*/
		posCode = "";
	//}
	var popupWin = window.open(fileUrl, winName,"menubar=no,toolbar=no,scrollbars=" + scrollBars + ",status=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight + "," + posCode);
	if (popupWin) popupWin.focus();
}

/**
* Обработка поля ввода
*/

function inputController()
{

}

inputController.object = null;
inputController.button = null;
inputController.classActive = '';
inputController.classInactive = '';
inputController.defaultValue = '';
inputController.isSubmitable = ''; 

inputController.prototype.init = function(inputId, buttonId)
{
    // настройки
    this.classInactive = 'inputFieldInactive';
    this.classActive = 'inputFieldActive';
    this.defaultValue = 'Введите поисковый запрос';
    this.isSubmitable = false;

    this.object = document.getElementById(inputId);
    this.button = document.getElementById(buttonId);
    
    this.object.className = this.classInactive;
    this.object.value = this.defaultValue;
    
    
    
}

inputController.prototype.clear = function()
{
    if ( this.object.value == this.defaultValue) {
        this.object.value = '';
    }
    this.object.className = this.classActive;
}

inputController.prototype.lostFocus = function()
{
    if (this.object.value == '' ||  this.object.value == this.defaultValue) {
        this.object.value = this.defaultValue;
        this.object.className = this.classInactive;
    }
}

inputController.prototype.keyPressed = function()
{
    if (this.object.value != '') {
        this.isSubmitable = true;
    } else {
        this.isSubmitable = false;
    }
}

inputController.prototype.submit = function()
{
    if (this.isSubmitable) {
        return true;
    } 
    else return false;
}

function set_values()
{
	if (document.forms['feedback'].name.value == ""){
		document.forms['feedback'].name.value = "Ваше имя";
		document.forms['feedback'].name.className = 'com_in_inactive';
	}
	if (document.forms['feedback'].email.value == ""){
		document.forms['feedback'].email.value = "Ваш Email";
		document.forms['feedback'].email.className = 'com_in_inactive';
	}
	if(document.forms['feedback'].phone.value == "")
		document.forms['feedback'].phone.value = "Ваш телефон";
		document.forms['feedback'].phone.className = 'com_in_inactive';
	if (msg.value == ""){
		msg.value = "Текст сообщения";	
		msg.className = 'com_in_inactive';
	}
	return;
}


function reset_value(name)
{
	switch (name) {
		case 'name':
			if (document.forms['feedback'].name.value == "Ваше имя")
				document.forms['feedback'].name.value = '';
			break;
		case 'email':
			if (document.forms['feedback'].email.value == "Ваш Email")
				document.forms['feedback'].email.value = '';
			break;
		case 'phone':
			if (document.forms['feedback'].phone.value == "Ваш телефон")
				document.forms['feedback'].phone.value = '';
			break;
		case 'message':
			if (msg.value == "Текст сообщения")
				msg.value = '';
			break;
	}
	return;
}

function submitPollVote(form)
{
    if ($('input[@name="vote"]:checked').val() == null) {
        alert('Выберите вариант ответа');
        return;
    }
    $.ajax({
        type : "POST",
        url  : "/poll/vote/",
        dataType: "json",
        data: 
        {
            poll: $('input[@name="poll"]').val(),
            vote: $('input[@name="vote"]:checked').val()
        },
        success: onAjaxSuccess,
        error: ajErr
    });
}

function ajErr(a, b)
{
    alert(b);
}

function getPollResults()
{
    $.post(
      '/poll/results-ajax/',
      {
        poll:  $('input[@name="poll"]').val() 
      },
      receivePollResults
);    
}

function onAjaxSuccess(obj)
{
    if (obj.state == 2) {
        getPollResults();
    } else {
        
    }
}

function receivePollResults(data)
{
    document.getElementById('poll-section').innerHTML = data;
    document.getElementById('pollSubmitButton').innerHTML = 'Спасибо, Ваш голос принят';
}

function makeNiceOls() {
	var alpha = new Array('a', 'b', 'c', 'd', 'e', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
	var ols = document.getElementsByTagName('OL');
	for(i=0; i<ols.length; i++) {
		if (ols[i].parentNode.tagName == 'DIV') {
			for(j=0, k=1; j<ols[i].childNodes.length; j++) {
				if (ols[i].childNodes[j].tagName == 'LI') {
					ols[i].childNodes[j].innerHTML = '<b>' + k++ + '.</b> ' + '<span>' + ols[i].childNodes[j].innerHTML + '</span>';
				}
			}
		} else {
			for(j=0, k=0; j<ols[i].childNodes.length; j++) {
				if (ols[i].childNodes[j].tagName == 'LI') {
					ols[i].childNodes[j].innerHTML = '<b>' + alpha[k%15] + '.</b> ' + '<span>' + ols[i].childNodes[j].innerHTML + '</span>';
					k++;
				}
			}
		}
	}
}

function generateFlash(movie, width, height, id, align, bgUrl, bLink)
{
  document.write('<div class="baner-flash" style="background:url(' + bgUrl + ') no-repeat left top;' + + (height==0 ? '' : ' height:'+height +'px;') + '"' + (width==0 ? '' : ' width="'+width +'"') + '>');
  document.write('<div class="itsflash"><object type="application/x-shockwave-flash" data="'+movie+(width==0 ? '' : '" width="'+width)+(height==0 ? '' : '" height="'+height)+'" id="'+id+'" align="'+align+'">');
  document.write('<param name="movie" value="'+movie+'" />');
  document.write('<param name="wmode" value="opaque" />');
  document.write('<param name="bgcolor" value="#ffffff" />');
  document.write('<param name="autoStart" value="-1" />');
  document.write('</object><a href="' + bLink + '" style="height: ' + height + 'px;"></a></div>');
  document.write('</div>');
}


function showGalleryImage(id)
{
    previewUrl = imagesArray[id][4];
    currentPreview.src = previewUrl;
    currentPreview.alt = imagesArray[id][1];
    imageTitle.innerHTML = imagesArray[id][0];
    //imageDescription.innerHTML = imagesArray[id][1];
    if (currentId > 0) {
        imagesArray[currentId][6].style.display = '';
        imagesArray[currentId][7].style.display = 'none';
    }
    imagesArray[id][6].style.display = 'none';
    imagesArray[id][7].style.display = '';
    currentId = id;
 
    imageInfo.innerHTML = '<a onclick="popupWindow(\'' + imagesArray[id][5] + '\', '+imagesArray[id][2]+', '+imagesArray[id][3]+', \'\', \'1\');return false;" href="'+imagesArray[id][5]+'" target="blank" >Оригинал</a> ('+imagesArray[id][2]+'&times;'+imagesArray[id][3]+')';
}

// {{{ IE, please stop flicker
try {
      document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
// }}}
