////////////////////////// Подключаем Ajax //////////////////////////
var xmlHttp = false;

try
{
	 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
	try
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e2)
	{
		xmlHttp = false;
	}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){
	xmlHttp = new XMLHttpRequest();
}

////////////////////////// Общие функции //////////////////////////
function getwindowHeight(){
	var windowHeight;
	if(window.innerHeight){ 
		windowHeight=window.innerHeight; 
	} else if(document.documentElement && document.documentElement.clientHeight){ 
		windowHeight=document.documentElement.clientHeight; 
	} else if(document.body){ 
		windowHeight=document.body.clientHeight; 
	}
	return windowHeight;
}

function getwindowWidth(){
	var windowWidth;
	if(window.innerWidth){ 
		windowWidth=window.innerWidth; 
	} else if(document.documentElement && document.documentElement.clientWidth){ 
		windowWidth=document.documentElement.clientWidth; 
	} else if(document.body){ 
		windowWidth=document.body.offsetWidth; 
	}
	return windowWidth;
}

function showBlock(name){
	var o = document.getElementById(name);
	if ('none' == o.style.display){
		o.style.display = '';
	}else{
		o.style.display = 'none';
	}
}

function getAttributes(node){   
	var ret = new Object();   
	if(node.attributes){ 
		for(var i=0; i<node.attributes.length; i++){   
			var attr = node.attributes[i];   
			ret[attr.name] = attr.value;   
		}
	}  
	return ret;   
}

function getElemText(node){
        return node.text || node.textContent || (function(node){
                var _result = "";
                if (node == null) {
                        return _result;
                }
                var childrens = node.childNodes;
                var i = 0;
                while (i < childrens.length) {
                        var child = childrens.item(i);
                        switch (child.nodeType) {
                                case 1: // ELEMENT_NODE
                                case 5: // ENTITY_REFERENCE_NODE
                                        _result += arguments.callee(child);
                                        break;
                                case 3: // TEXT_NODE
                                case 2: // ATTRIBUTE_NODE
                                case 4: // CDATA_SECTION_NODE
                                        _result += child.nodeValue;
                                        break;
                        }
                        i++;
                }
                return _result;
        }(node));
 }

////////////////////////// Авторизация //////////////////////////
function autorize(){
	poststr = "login="+document.getElementById("login").value+"&pass="+document.getElementById("pass").value;
	url='/scripts/autorization.class.php';
	xmlHttp.open('POST', url);
	xmlHttp.onreadystatechange = resultAutorize;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
}

function resultAutorize(){
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText;
		if(response == 'ok') {window.location.reload();}
		else {alert('Указанные данные не найдены!')}
		xmlHttp.abort();
	}
}

function unautorize()
{
	poststr = "null";
	url='/scripts/unautorization.class.php';
	xmlHttp.open('POST', url);
	xmlHttp.onreadystatechange = resultUnAutorize;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", poststr.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
}
		//Обработка ответа сервера на создание нового документа
function resultUnAutorize() {
	if (xmlHttp.readyState == 4) {
		window.location.reload();
		xmlHttp.abort();
	}
}

////////////////////////// Функции для товара //////////////////////////
function addBasket(product_id){
	var cnt_all = 1;
	var product_size = document.getElementById("product_size") ? document.getElementById("product_size").value : "";
	var poststr = "";

	if(cnt_all && cnt_all != 0){
		poststr += "&cnt_all=" + cnt_all + "&product_size=" + product_size;
	}

	if(poststr){
		poststr = "product_id=" + product_id + poststr;
		url='/scripts/addbasket.class.php';
		SendRequest("post", url, poststr, resultAddBasket);
	}
}
		//Обработка ответа сервера на создание нового документа
function resultAddBasket(Request) {
	var response = Request.responseText;
	document.getElementById("idCartModule").innerHTML = response;
	alert("Товар добавлен в корзину.");
	//alert(response);
	//document.getElementById("divbskt").innerHTML = response;
	//document.getElementById("tdbasketref").innerHTML = '<a href="/basket/" style="font-size:9px; color:#fff;">оформить заказ</a>';
	//if(confirm("Товар добавлен. Вы хотите перейти к оформлению заказа сейчас?")){
	//	window.location = "http://www.lensation.ru/basket/";
	//}else{
	//	return '';
	//}
}

function getBanner() {
	var response = '';
	response += '<table cellpadding="0" cellspacing="0" style="margin-top:9px;" width="198px">';
	response += '<tr>';
	response += '	<td width="62px"><a href="http://vkontakte.ru/club5373722" target="_blank"><img src="/image/vkontakte.png" border="0" alt="Вконтакте"></a>';
	response += '	</td>';
	response += '	<td width="6px">';
	response += '	</td>';
	response += '	<td witdh="62px"><a href="http://rus-ultras.livejournal.com/" target="_blank"><img src="/image/livejournal.png" border="0" alt="LiveJournal"></a>';
	response += '	</td>';
	response += '	<td width="6px">';
	response += '	</td>';
	response += '	<td width="62px"><a href="http://twitter.com/rusultras" target="_blank"><img src="/image/twitter.png" border="0" alt="Twitter"></a>';
	response += '	</td>';
	response += '</tr>';
	response += '</table>';
	document.write(response);
}

////////////////////////// Функции для подбора //////////////////////////
function getPodborForm(){
	//var categoryId = document.getElementById("category_id") ? document.getElementById("category_id").value : "";
	var producerId = document.getElementById("producer_id") ? document.getElementById("producer_id").value : "";
	var categoryType = document.getElementById("category_type") ? document.getElementById("category_type").value : "";
	var size = document.getElementById("size") ? document.getElementById("size").value : "";
	var poststr = "&category_type=" + categoryType + "&producer_id=" + producerId + "&size=" + size;

	var clockForm = '';
	clockForm += '<table cellpadding="0" cellspacing="0" style="margin:9px;" width="181px">';
	clockForm += '<tr>';
	clockForm += '	<td>';
	clockForm += '		<img src="/image/podbor.jpg" width="181px" style="margin:0 0 9px 0; border:0; display:block;">';
	clockForm += '	</td>';
	clockForm += '</tr>';
	clockForm += '<tr valign="middle">';
	clockForm += '	<td style="font-family:Verdana; font-size:14px;">';
	clockForm += '	<img src="/image/clock.jpg" width="181px">';
	clockForm += '	</td>';
	clockForm += '</tr>';
	clockForm += '</table>';

	document.getElementById("podborForm").innerHTML = clockForm;

	if(poststr){
		poststr = "section=catalogue&action=search_form" + poststr;
		url='/detail.php';
		SendRequest("post", url, poststr, resultPodborForm);
	}
}
		//Обработка ответа сервера на создание нового документа
function resultPodborForm(Request) {
	var response = Request.responseText;
	document.getElementById("podborForm").innerHTML = response;
}
