/* -------------------------- */
/*   XMLHTTPRequest Enable    */
/* -------------------------- */
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		request_type = new XMLHttpRequest();
	}
	return request_type;
}
var http = createObject();
var http2 = createObject();

/* -------------------------- */
/*           PHOTO            */
/* -------------------------- */

function showPhoto(name){	document.getElementById('photo').innerHTML='<img src="/document/photo/'+name+'" />';
}

/* -------------------------- */
/*            NEWS            */
/* -------------------------- */

function timering(){	this.timerID=null;
}
oTimer=new timering();
function showNews(id){	clearTimeout(oTimer.timerID);	var last='';
	document.getElementById('last_news').innerHTML='';
	document.getElementById('image').innerHTML='';	for(i=1;i<5;i++){
		last=last+'<div class="';
		if(i==id){			last=last+'show';
		}else{
			last=last+'nws';
		}
		last=last+'" id="n'+i+'">';
		last=last+'<a href="/news/'+news_id[i]+'.html">';
		if(i!=id){			last=last+'<div class="img">';
			if(news_img[i]==''){			}else{				last=last+'<img src="/images/news/'+news_id[i]+'_preview.'+news_img[i]+'" />';
			}
			last=last+'</div>';
		}
		last=last+news_txt[i]+'</a></div>';
		if(i<4) last=last+'<div class="width-brdr"></div>';
	}
	document.getElementById('last_news').innerHTML=last;
	if(news_img[id]==''){
		document.getElementById('image').innerHTML='';
	}else{
		document.getElementById('image').innerHTML='<img src="/images/news/'+news_id[id]+'.'+news_img[id]+'" />';
	}
	var next = id+1;
	if(next>4) next=1;
	oTimer.timerID = setTimeout('showNews('+next+')',10000);
}

/* -------------------------- */
/*            FIND            */
/* -------------------------- */

function find_str_f(){	if(document.getElementById('find').value=='Поиск по сайту'){		document.getElementById('find').value='';
	}
}
function find_str_b(){
	if(document.getElementById('find').value==''){
		document.getElementById('find').value='Поиск по сайту';
	}
}

function dwnfSend(){	var dir=document.getElementById('dir').value;
	if(dir>0){		return true;
	}else{		return false;
	}
}
function chngY(){	var year=document.getElementById('year').value;
	if(year>0){
		var nocache = Math.random();
		http.open('get', '/includes/js/month.php?year='+year+'&nocache = '+nocache);
		http.onreadystatechange = month_output;
		http.send(null);
	}
}
function month_output() {
	if(http.readyState == 4){
		var response = http.responseText;
		if(response == ''){
			document.getElementById('dnwfm').innerHTML = '&nbsp;';
		}else{
			document.getElementById('dnwfm').innerHTML = response;
		}
	}
}

/* -------------------------- */
/*           HEADER           */
/* -------------------------- */

function initHeader(nxt){	var where=document.getElementById('where').innerHTML;
	chngHeader(nxt,where)
}

function chngHeader(nxt,where){    if(where!='noChng'){		for(i=1;i<=7;i++){			document.getElementById('h'+i).setAttribute('class', 'hide');
			document.getElementById('f'+i).setAttribute('class', 'hide');
		}
		document.getElementById('h'+nxt).setAttribute('class', 'show');
		document.getElementById('f'+nxt).setAttribute('class', 'show');
		document.getElementById('where').innerHTML=where.toUpperCase();
		if(nxt==1){			//Белый, синий
			//document.getElementById("txt").style.color="#fff";
			document.getElementById("where").style.color="#fff";
	        elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody2.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright2.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody.png')";
			document.getElementById("tright2").style.background="url('/images/tright.png')";
		}
		if(nxt==2){
			//Синий, белый
			//document.getElementById("txt").style.color="#04113b";
			document.getElementById("where").style.color="#04113b";
	        elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#04113b";
	        }
			document.getElementById("where").style.borderColor="#04113b";
			document.getElementById("tleft1").style.background="url('/images/tleft.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody2.png')";
			document.getElementById("tright2").style.background="url('/images/tright2.png')";
		}
		if(nxt==3){
			//Белый, белый
			//document.getElementById("txt").style.color="#fff";
			document.getElementById("where").style.color="#fff";
	        elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody.png')";
			document.getElementById("tright2").style.background="url('/images/tright.png')";
		}
		if(nxt==4){
			//Белый, белый
			//document.getElementById("txt").style.color="#fff";
			document.getElementById("where").style.color="#fff";
			elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody.png')";
			document.getElementById("tright2").style.background="url('/images/tright.png')";
		}
		if(nxt==5){
			//Белый, белый
			//document.getElementById("txt").style.color="#fff";
			document.getElementById("where").style.color="#fff";
			elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody2.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright2.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody2.png')";
			document.getElementById("tright2").style.background="url('/images/tright2.png')";
		}
		if(nxt==6){
			//Белый, белый
			//document.getElementById("txt").style.color="#fff";
			document.getElementById("where").style.color="#fff";
			elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody2.png')";
			document.getElementById("bloglink").style.color="#04113b";
			document.getElementById("tright1").style.background="url('/images/tright2.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody.png')";
			document.getElementById("tright2").style.background="url('/images/tright.png')";
		}
		if(nxt==7){
			//Синий, синий
			//document.getElementById("txt").style.color="#04113b";
			document.getElementById("where").style.color="#fff";
	        elems = document.getElementById("menu").getElementsByTagName("a");
	        for (i = 0;i<elems.length;i++) {
	        	elems[i].style.color="#fff";
	        }
			document.getElementById("where").style.borderColor="#fff";
			document.getElementById("tleft1").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody1").style.background="url('/images/tbody2.png')";
			document.getElementById("bloglink").style.color="#fff";
			document.getElementById("tright1").style.background="url('/images/tright2.png')";
			document.getElementById("tleft2").style.background="url('/images/tleft2.png')";
			document.getElementById("tbody2").style.background="url('/images/tbody2.png')";
			document.getElementById("tright2").style.background="url('/images/tright2.png')";
		}
	}
}

/* -------------------------- */
/*          COMMENT           */
/* -------------------------- */

function com_str_f(){
	if(document.getElementById('com_user').value=='Ваше имя'){
		document.getElementById('com_user').value='';
	}
}
function com_str_b(){
	if(document.getElementById('com_user').value==''){
		document.getElementById('com_user').value='Ваше имя';
	}
}

function test(){
	var obj = document.getElementById("com_txt");
	var com_user = document.getElementById("com_user");
	if(com_user.value == "Ваше имя"){
		alert('Представьтесь!');
		return false;
	}else{
		if(obj.value == ""){
			alert('Вы не ввели комментарий!');
			return false;
		}else{
			obj.value = obj.value.replace(/'/g, "`");
			obj.value = obj.value.replace(/"/g, '&quot;');
			return true;
		}
	}
}
function quote(author){
	var obj = document.getElementById("com_txt");
	obj.focus();
	if(obj.value == ''){
		obj.value = '[B]' + author + '[/B], ';
	}else{
		obj.value = obj.value + '\n' + '[B]' + author + '[/B], ';
	}
}
function tag(tags){
	var obj = document.getElementById("com_txt");
	obj.focus();

	if(document.selection){
		var s = document.selection.createRange();
		s.text = '['+tags+']' + s.text + '[/'+tags+']';
	}else{
		var len = obj.value.length;
		var start = obj.selectionStart;
		var end = obj.selectionEnd;

		var scrollTop = obj.scrollTop;
		var scrollLeft = obj.scrollLeft;

		var sel = obj.value.substring(start, end);
		var rep = '['+tags+']' + sel + '[/'+tags+']';
		obj.value =  obj.value.substring(0,start) + rep + obj.value.substring(end,len);
	}
}
function chPhoto(host,id,exp){
	photo_fn='http://'+host+'/images/shop/'+id+'.'+exp;
	document.getElementById('main_photo').innerHTML = '<img src="'+photo_fn+'" \>';
}
