﻿function Show( id )
{
	var content = document.getElementById( id );
	//alert( content.style.display );
	content.style.display = '';
	content.style.visibility = 'visible';	
	//alert( content.style.display );	
}

function Hide( id )
{
	var content = document.getElementById( id );
	//content.style.visibility = 'collapse';	
	content.style.visibility = 'hidden';
	content.style.display = 'none';
}

function show_displaydiv(id)
{
	div = document.getElementById(id);
	div.style.display = 'block';
	div.style.height = document.body.scrollHeight + 'px';
}

function hide_div(id)
{
	document.getElementById(id).style.display = 'none';
}

function insert_image(folder, prefix, postfix, containerid, number, w, h)
{
	var photos = document.getElementById('smallphotos');
	var alinks = photos.getElementsByTagName('a');
	var last =  alinks.length;
	
	number = number * 1;
	w = w * 1;
	h = h * 1;
	
	if( number == 1 )
	{
		btn_prev = '';
	} else {
		var prevnumber = (number - 1) * 1;
		var prevlink = document.getElementById('photo_' + prevnumber);
		//alert('prev href: ' + prevlink.href);
		btn_prev = '<a class="prev" href="' + prevlink.href + '"><img src="/images/i.gif" width="40" height="41" border="0" title="На один назад" alt="На один назад"></a>';
	}
	
	if( number == last )
	{
		btn_next = '';
	} else {
		var nextnumber = (number + 1) * 1;
		var nextlink = document.getElementById('photo_' + nextnumber);
		//alert('next href: ' + nextlink.href);
		btn_next = '<a class="next" href="' + nextlink.href + '"><img src="/images/i.gif" width="40" height="41" border="0" title="На один вперед" alt="На один вперед"></a>';
	}
	
	div_w = (w + 10) * 1;
	div_h = (h + 45) * 1;

    tbl_h = document.body.clientHeight;
	tbl_t = document.body.scrollTop;

    divHTML='<div class="bigphoto_table" style="width: ' + div_w + 'px; height: ' + tbl_h + 'px; margin-top: ' + tbl_t + 'px;">' + 
		'<div class="bigphoto_tr" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
		'<div class="bigphoto_td" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
		'<div class="bg_bigphoto" style="background-image: url(' + folder + prefix + number + postfix + '); width: ' + div_w + 'px; height: ' + h + 'px;">' + 
			'<div class="buttons">' + 
				btn_prev + 
				btn_next + 
			'</div>' + 
		'</div>' + 
		'<div class="links" style="width: ' + div_w + 'px;">' + 
			'<div class="right"><a class="red" href=javascript:hide_displaydiv("' + containerid + '");>Закрыть</a></div>' + 
		'</div>' + 
		'</div>' + 
		'</div>' + 
	'</div>';
	
	//alert(divHTML);
	document.getElementById(containerid).innerHTML = divHTML;
}

function set_centers(containerid, w, h)
{
	w = w * 1;
	h = h * 1;
	
	//div_w = (w + 10) * 1;
	//div_h = (h + 45) * 1;
	
	div_w = w;
	div_h = h;

    tbl_h = document.body.clientHeight;
	tbl_t = document.body.scrollTop;

    divHTML='<div class="bigphoto_table" style="width: ' + div_w + 'px; height: ' + tbl_h + 'px; margin-top: ' + tbl_t + 'px;">' + 
		'<div class="bigphoto_tr" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
		'<div class="bigphoto_td" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
			document.getElementById(containerid).innerHTML + 
		'</div>' + 
		'</div>' + 
	'</div>';
	
	alert(divHTML);
	document.getElementById(containerid).innerHTML = divHTML;
}

function ajaxpage_centers(url, containerid, w, h){
	var page_request = false
	
	try {
		// Firefox, Opera 8.0+, Safari, IE7+
		page_request = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
	} catch (e) {
		// Internet Explorer
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			page_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
		
	page_request.onreadystatechange=function(){
		loadpage_centers(page_request, containerid, w, h)
	}

	page_request.open('get', url, true)
	page_request.send(null)
}

function ajaxpage(url, containerid){
	var page_request = false
	
	try {
		// Firefox, Opera 8.0+, Safari, IE7+
		page_request = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
	} catch (e) {
		// Internet Explorer
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			page_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
		
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}

	page_request.open('get', url, true)
	page_request.send(null)
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadpage_centers(page_request, containerid, w, h){
	w = w * 1;
	h = h * 1;
	
	div_w = w;
	div_h = h;

    tbl_h = document.body.clientHeight;
	tbl_t = document.body.scrollTop;
    
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML = '<div class="bigphoto_table" style="width: ' + div_w + 'px; height: ' + tbl_h + 'px; margin-top: ' + tbl_t + 'px;">' + 
		'<div class="bigphoto_tr" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
		'<div class="bigphoto_td" style="width: ' + div_w + 'px; height: ' + div_h + 'px;">' + 
			page_request.responseText + 
		'</div>' + 
		'</div>' + 
		'</div>';
	}
}
