var get = function(id) { return document.getElementById(id); }

function tabSw(t, v) {

	for(i = 0; i < 20; i++) try {
			document.getElementById('tab' + t + 'Sw' + i).className = 'inactive';
	} catch(e) {};
	document.getElementById('tab' + t + 'Sw' + v).className = 'active';

	for(i = 0; i < 20; i++) try {
			document.getElementById('tab' + t + 'var' + i).style.display = 'none';
	} catch(e) {};
	try {
		document.getElementById('tab' + t + 'Sw' + v).className = 'active';
		document.getElementById('tab' + t + 'var' + v).style.display = '';
	} catch(e) {};

}

function cms_buydvd(id) {
	try {
	ajax.query(id, false);
	} catch(e) {};
}

function shots() {
	if (document.getElementById('shots').style.overflow == 'hidden') document.getElementById('shots').style.overflow = 'auto';
}

function Ajax() {

	this.query = function(id, async) {
		var http = this.http();
		var url = 'id=' + id + '&ac=' + Math.random();

		http.open('POST', '/my/cart/do.add_cart.id.' + id + '.html', async ? false : true);
		http.setRequestHeader('Content-Type', 'application/octet-stream');
		http.onreadystatechange = function() {
		if(http.readyState == 4) {
			try {
				eval('response = ' + http.responseText + ';');
				if(response['method']) eval(response['method'] + '(response)');
			} catch (e) {
				alert('Îøèáêà: ' + e.message + '\n\nDebug:\n'+http.responseText);
			}
		}
	}
		http.send(url);
	}

	this.http = function() {
	    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;
	}

}

ajax = new Ajax;

function set_content(id, html) {
	document.getElementById(id).innerHTML = html;
}

function auto_set_content(r) {
	set_content(r['div_id'], r['html']);
}

function refresh_cart(r) {
	auto_set_content(r);
	try {
	var buy = get('buy' + r['id']);
	var order = get('order' + r['id']);
	buy.style.display = 'none';
	order.style.display = '';
	} catch(e) {};
}



function hint(title, text) {
	w = 400;
	h = 200;
	var h_window = window.open('', h_window, 'left=' + ((screen.width - w)/2) + ',top=' + ((screen.height - h)/2 - 50) + ',width=' + (w+20) + ',height=' + (h+20));
	h_window.document.write('<title>' + title + '</title><body style="margin:10px;cursor:pointer;" onClick="window.close()">');
	h_window.document.write('<p><b style="font-family:arial;font-size:14	px">' + title + '</b></p><p style="font-family:arial;font-size:12px">' + text + '</p></body>');
	h_window.focus();
}


function cmsSwitch() {
	if(event.keyCode == 123) document.location.href = admin_uri;
}