﻿function showPic(info,file,widt,heigh,x) {
var w=(window.screen.availWidth-widt)/2;
var h=(window.screen.availHeight-heigh)/2;
var config;
var w_badb=window.open('#', 'avi'+x, config='height='+heigh+',width='+widt+',menubar=0,left='+w+',top='+h);
w_badb.document.open();

w_badb.document.write('<html><head><title>'+info+'</title></head><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"><img src="'+file+'" width="'+widt+'" height="'+heigh+'" alt="'+info+'" border="0" onclick="window.close();"></body></html>');
w_badb.document.close();
return false;
}

var req;
var curItemId;
function Initialize()
{

	try
	{
		req=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			req=null;
		}
	}

	if(!req&&typeof XMLHttpRequest!="undefined")
	{
		req=new XMLHttpRequest();
	}
	
}

function SendQuery(itemId)
{
	Initialize();
	var selColor=document.getElementById("color"+itemId);
	var url="/basket/addcart.aspx?id="+itemId+"&c="+selColor.value;
		
	if(req!=null)
	{
		req.onreadystatechange = Process;
		req.open("GET", url, true);
        req.send(null);
        
	}
	
}
var _tmp;
var _oInt;
function Process()
{
var d=document.getElementById("h"+curItemId);
	if (req.readyState == 4) 
        {
        // only if "OK"
			if (req.status == 200) 
			{
				if(req.responseText=="")
					;
					//
				else
				{
					//
					var s=document.getElementById("_ctl0_basketSum");
					var c=document.getElementById("_ctl0_basketCount");
					var x =new String();
					x=req.responseText;
					var del=x.indexOf("*");
					
					//var bsk=document.getElementById("basket_bsk");
					//bsk.style.display="block";
					s.innerHTML=x.substr(0,del)+" руб.";
					c.innerHTML=x.substr(del+1);
					d.innerHTML="Товар добавлен в заказ!"
					_tmp=d;
					_oInt=window.setInterval("panelHider()",1000);
					
				}
			}
			else 
			{
				
				d.innerHTML="Ошибка!<br>"+req.statusText;
			}
		}
}
function panelHider()
{
_tmp.style.display="none";
_tmp.innerText="Добавление в заказ";

 window.clearInterval(_oInt);
}

function addItem(itemId)
{
 if(_tmp!=null)
 {
	_tmp.style.display="none";
 }
	curItemId=itemId;
	var d=document.getElementById("h"+itemId);
	d.style.display="inline";
	SendQuery(itemId);
}


function showItemInfo(i)
{
var heigh=320;
var widt=450;
var w=(window.screen.availWidth-widt)/2;
var h=(window.screen.availHeight-heigh)/2;

window.open('iteminfo.aspx?id='+i, 'avi'+i, config='height='+heigh+',width='+widt+',menubar=0,left='+w+',top='+h);	
}

function checkINN()
{
var c=document.getElementById("innValid");
var b="ie";
if(c==null)
{
	b="ot";
	c=document.getElementById("innSpan");
}

var i=document.getElementById("inn");

if(i.value.length==0 && b=="ie")
{
	c.style.display="inline";
	i.focus();
    return false;
}


var re =/(?:\d{10}|\d{12})\/\d{9}/;
      if (i.value.match(re)==null)
        {
       c=document.getElementById("innRegValid");
	   if(c==null)
		{
		b="ot";
		c=document.getElementById("innSpan");
		}

            if(b=="ot")
            {
				c.innerHTML="Введите корректный ИНН/КПП!";
				c.style.display="inline";
			}
            i.focus();
            return false;
        }
c.style.display="none";
getOrgInfo();

}

function getOrgInfo()
{
	Initialize();
	var i=document.getElementById("inn");
	var url="/basket/getorginfo.aspx?id="+i.value;
		
	if(req!=null)
	{
		req.onreadystatechange = ProcessOrgInfo;
		req.open("GET", url, true);
        req.send(null);

	}
	

}

function ProcessOrgInfo()
{
if(req.readyState == 4)
	{
        if(req.status == 200)
        {
           var doc = req.responseXML;
           var root = doc.documentElement;
           var cNode=root.childNodes;
           var c=document.getElementById("innSpan");
		   if(cNode[0].firstChild.nodeValue==-1)
		   {
				c.innerHTML="Информация не найдена!";
				c.style.display="inline";
		   }
		   else
		   {
				c.style.display="none";
				document.getElementById("yurName").value=cNode[1].firstChild.nodeValue;
				document.getElementById("yurAdres").value=cNode[2].firstChild.nodeValue;
				document.getElementById("bik").value=cNode[3].firstChild.nodeValue;
				document.getElementById("rs").value=cNode[4].firstChild.nodeValue;
				document.getElementById("fio").value=cNode[5].firstChild.nodeValue;
				document.getElementById("tel").value=cNode[6].firstChild.nodeValue;
				document.getElementById("mail").value=cNode[7].firstChild.nodeValue;
				document.getElementById("adres").value=cNode[8].firstChild.nodeValue;
		   }
        }
    }       
}

function checkMail()
{
var c=document.getElementById("innValid");
var b="ie";
if(c==null)
{
	b="ot";
	c=document.getElementById("innSpan");
}

var i=document.getElementById("mail");

if(i.value.length==0 && b=="ie")
{
	c.style.display="inline";
	i.focus();
    return false;
}

var re =/([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;
      if (i.value.match(re)==null)
        {
       c=document.getElementById("innRegValid");
	   if(c==null)
		{
		b="ot";
		c=document.getElementById("innSpan");
		}

            if(b=="ot")
            {
				c.innerHTML="Введите корректный E-mail адрес!";
				c.style.display="inline";
			}
            i.focus();
            return false;
        }
c.style.display="none";
getUserInfo();
}


function getUserInfo()
{
	Initialize();
	var i=document.getElementById("mail");
	var url="/basket/getuserinfo.aspx?id="+encodeURIComponent(i.value);
		
	if(req!=null)
	{
		req.onreadystatechange = ProcessUserInfo;
		req.open("GET", url, true);
        req.send(null);

	}
	

}

function ProcessUserInfo()
{
if(req.readyState == 4)
	{
        if(req.status == 200)
        {
           var doc = req.responseXML;
           var root = doc.documentElement;
           var cNode=root.childNodes;
           var c=document.getElementById("innSpan");
		   if(cNode[0].firstChild.nodeValue==-1)
		   {
				c.innerHTML="Информация не найдена!";
				c.style.display="inline";
		   }
		   else
		   {
				c.style.display="none";
				document.getElementById("fio").value=cNode[1].firstChild.nodeValue;
				document.getElementById("tel").value=cNode[2].firstChild.nodeValue;
				document.getElementById("mail").value=cNode[3].firstChild.nodeValue;
				document.getElementById("adres").value=cNode[4].firstChild.nodeValue;
		   }
        }
    }       
}