
// *********************************************************************************************
function ChkBasketPcs( num, pcs )
	{
	if( num <= pcs ) { alert("Товар добавлен в корзину"); return true; }
	alert("ОШИБКА: Кол-во заказываемого товара не может превышать его наличие...");
	return false;
	}

// *********************************************************************************************
function Confirm( str )
{
if( confirm( str ) ) return true;
return false;
}

// *********************************************************************************************
function GetText(FormElement)
{
  var nSelectedIndex;
  var strText = "";
  switch (FormElement.type)
  {
    case "select-one" :
    case "select-multiple" :
      nSelectedIndex = FormElement.selectedIndex;
      if (nSelectedIndex == -1)
        nSelectedIndex = 0;
      strText = FormElement.options[nSelectedIndex].text;
      break;
    case "checkbox" :
      strText = FormElement.value;
      break;
    case "text" :
    case "password" :
    case "hidden" :
    case "textarea" :
    case "radio":
      strText = FormElement.value;
      break;
    default :
      strText = ""
  }
  return Trim(strText);
}


// *********************************************************************************************
function trim(str)
	{
	var newstr = str.replace(/^\s*(.+?)\s*$/, "$1");
	if (newstr == " ") { return "";	}
	return newstr;
	}

// *********************************************************************************************
function drop_spaces(str)
	{
	var newstr = trim(str);
	return newstr.replace(/(\s)+/g, "");
	}

// *********************************************************************************************
function isValidEmail( email )
	{
	var template = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
	email = drop_spaces( email );
	if (template.test(email)) { return true; }
	return false;
	// return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
	}
// *********************************************************************************************
function isValidPhone( phone )
	{
	var template = /^([0-9\+\-\s\(\)])+$/;
	email = drop_spaces( phone );
	if( phone.length < 7 ) { return false; }
	if (template.test(phone)) { return true; }
	return false;
	}
// *********************************************************************************************
function switchTIRE(trid,odd)
	{
	var ptrid = document.getElementById('r-'+trid);
	var oForm = document.getElementById('s-'+trid);
	if(document.getElementById(trid).style.visibility == "visible")
		{
		document.getElementById(trid).style.visibility = "hidden";
		document.getElementById(trid).style.display = "none";
		ptrid.style.visibility = "visible";
		ptrid.style.display = "table-row";
		}
	else
		{
		document.getElementById(trid).style.visibility = "visible";
		document.getElementById(trid).style.display = "table-row";
		// document.oForm.pcs.focus();
		ptrid.style.visibility = "hidden";
		ptrid.style.display = "none";
		// ptrid.style.borderBottom = "0";
		// document.getElementById(trid).style.borderTop = "0";
		showTire(trid,odd);
		}
	}

// *********************************************************************************************
function switchDISK(trid,odd)
	{
	var ptrid = document.getElementById('r-'+trid);
	var oForm = document.getElementById('s-'+trid);
	if(document.getElementById(trid).style.visibility == "visible")
		{
		document.getElementById(trid).style.visibility = "hidden";
		document.getElementById(trid).style.display = "none";
		ptrid.style.visibility = "visible";
		ptrid.style.display = "table-row";
		}
	else
		{
		document.getElementById(trid).style.visibility = "visible";
		document.getElementById(trid).style.display = "table-row";
		// document.oForm.pcs.focus();
		ptrid.style.visibility = "hidden";
		ptrid.style.display = "none";
		// ptrid.style.borderBottom = "0";
		// document.getElementById(trid).style.borderTop = "0";
		showDisk(trid,odd);
		}
	}
// *********************************************************************************************
function switchACCUM(trid,odd)
	{
	var ptrid = document.getElementById('r-'+trid);
	var oForm = document.getElementById('s-'+trid);
	if(document.getElementById(trid).style.visibility == "visible")
		{
		document.getElementById(trid).style.visibility = "hidden";
		document.getElementById(trid).style.display = "none";
		ptrid.style.visibility = "visible";
		ptrid.style.display = "table-row";
		}
	else
		{
		document.getElementById(trid).style.visibility = "visible";
		document.getElementById(trid).style.display = "table-row";
		// document.oForm.pcs.focus();
		ptrid.style.visibility = "hidden";
		ptrid.style.display = "none";
		// ptrid.style.borderBottom = "0";
		// document.getElementById(trid).style.borderTop = "0";
		showAccum(trid,odd);
		}
	}

// *********************************************************************************************
function switchACC(trid,odd)
	{
	var ptrid = document.getElementById('r-'+trid);
	var oForm = document.getElementById('s-'+trid);
	if(document.getElementById(trid).style.visibility == "visible")
		{
		document.getElementById(trid).style.visibility = "hidden";
		document.getElementById(trid).style.display = "none";
		ptrid.style.visibility = "visible";
		ptrid.style.display = "table-row";
		}
	else
		{
		document.getElementById(trid).style.visibility = "visible";
		document.getElementById(trid).style.display = "table-row";
		// document.oForm.pcs.focus();
		ptrid.style.visibility = "hidden";
		ptrid.style.display = "none";
		// ptrid.style.borderBottom = "0";
		// document.getElementById(trid).style.borderTop = "0";
		showAt(trid,odd);
		}
	}
// *********************************************************************************************
function switchCAPS(trid,odd)
	{
	var ptrid = document.getElementById('r-'+trid);
	var oForm = document.getElementById('s-'+trid);
	if(document.getElementById(trid).style.visibility == "visible")
		{
		document.getElementById(trid).style.visibility = "hidden";
		document.getElementById(trid).style.display = "none";
		ptrid.style.visibility = "visible";
		ptrid.style.display = "table-row";
		}
	else
		{
		document.getElementById(trid).style.visibility = "visible";
		document.getElementById(trid).style.display = "table-row";
		// document.oForm.pcs.focus();
		ptrid.style.visibility = "hidden";
		ptrid.style.display = "none";
		// ptrid.style.borderBottom = "0";
		// document.getElementById(trid).style.borderTop = "0";
		showCaps(trid,odd);
		}
	}

// *********************************************************************************************
// получение описания товара
function showTire(article,odd)
	{
        var cont = document.getElementById('t-'+article);
        var loading = document.getElementById(article);

        cont.innerHTML = loading.innerHTML;

        var http = createRequestObject();
        if( http )
	        {
	        http.open('get', 'tiresdetail.php?t='+article+'&odd='+odd);
		http.onreadystatechange = function ()
			{
			if(http.readyState == 4)
				{
				cont.innerHTML = http.responseText;
				}
			}
		http.send(null);
		}
	else
		{
		document.location = 'tiresdetail.php?t='+article+'&odd='+odd;
		}
	}

// *********************************************************************************************
function showDisk(article,odd)
	{
        var cont = document.getElementById('t-'+article);
        var loading = document.getElementById(article);

        cont.innerHTML = loading.innerHTML;

        var http = createRequestObject();
        if( http )
	        {
	        http.open('get', 'dimsdetail.php?t='+article+'&odd='+odd);
		http.onreadystatechange = function ()
			{
			if(http.readyState == 4)
				{
				cont.innerHTML = http.responseText;
				}
			}
		http.send(null);
		}
	else
		{
		document.location = 'dimsdetail.php?t='+article+'&odd='+odd;
		}
	}

// *********************************************************************************************
function showAccum(article,odd)
	{
        var cont = document.getElementById('t-'+article);
        var loading = document.getElementById(article);

        cont.innerHTML = loading.innerHTML;

        var http = createRequestObject();
        if( http )
	        {
	        http.open('get', 'akbdetail.php?t='+article+'&odd='+odd);
		http.onreadystatechange = function ()
			{
			if(http.readyState == 4)
				{
				cont.innerHTML = http.responseText;
				}
			}
		http.send(null);
		}
	else
		{
		document.location = 'akbdetail.php?t='+article+'&odd='+odd;
		}
	}
// *********************************************************************************************
function showAt(article,odd)
	{
        var cont = document.getElementById('t-'+article);
        var loading = document.getElementById(article);

        cont.innerHTML = loading.innerHTML;

        var http = createRequestObject();
        if( http )
	        {
	        http.open('get', 'atdetail.php?t='+article+'&odd='+odd);
		http.onreadystatechange = function ()
			{
			if(http.readyState == 4)
				{
				cont.innerHTML = http.responseText;
				}
			}
		http.send(null);
		}
	else
		{
		document.location = 'atdetail.php?t='+article+'&odd='+odd;
		}
	}
// *********************************************************************************************
function showCaps(article,odd)
	{
        var cont = document.getElementById('t-'+article);
        var loading = document.getElementById(article);

        cont.innerHTML = loading.innerHTML;

        var http = createRequestObject();
        if( http )
	        {
	        http.open('get', 'capsdetail.php?t='+article+'&odd='+odd);
		http.onreadystatechange = function ()
			{
			if(http.readyState == 4)
				{
				cont.innerHTML = http.responseText;
				}
			}
		http.send(null);
		}
	else
		{
		document.location = 'capsdetail.php?t='+article+'&odd='+odd;
		}
	}


// post functions ************************************************************************

function getRequestBody( oForm )
{
var aParams = new Array();
for(var i = 0; i < oForm.elements.length; i++)
	{
	var sParam = encodeURIComponent(oForm.elements[i].name);
	sParam += "=";
	sParam += encodeURIComponent(oForm.elements[i].value);
	aParams.push(sParam);
	}
return aParams.join("&");
}

function sendRequest( FormId )
{
var oForm = document.getElementById( FormId );
// alert( FormName );
var sBody = getRequestBody(oForm);
// var oXmlHttp = createXMLHttp();
var oXmlHttp = createRequestObject();
oXmlHttp.open("POST", oForm.action, true);
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

oXmlHttp.onreadystatechange = function()
	{
	if(oXmlHttp.readyState == 4)
		{
		if(oXmlHttp.status == 200)
			{
			RefreshBasketResult(oXmlHttp.responseText);
			}
		else
			{
			RefreshBasketResult("Ошибка: " + oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);
}

function RefreshBasketResult(sText)
{
var sElem = document.getElementById("BasketStatus");
sElem.innerHTML = sText;
}
// end post functions ************************************************************************

//
function RemoveFromBasket(Id)
	{
	// var oXmlHttp = createXMLHttp();
	var oXmlHttp = createRequestObject();
	oXmlHttp.open("GET","small_cart.php?noid="+Id,true);
	oXmlHttp.onreadystatechange = function()
		{
		if(oXmlHttp.readyState == 4)
			{
			if(oXmlHttp.status == 200)
				{
				RefreshBasketResult(oXmlHttp.responseText);
				}
			else
				{
				// displayCustomerInfo("Ошибка: " + oXmlHttp.statusText);
				}
			}
		};
	oXmlHttp.send(null);
	}

// создание ajax объекта
function createRequestObject()
	{
        try { return new XMLHttpRequest() }
        catch(e)
		{
		try { return new ActiveXObject('Msxml2.XMLHTTP') }
		catch(e)
			{
			try { return new ActiveXObject('Microsoft.XMLHTTP') }
			catch(e) { return null; }
			}
		}
	}

// старая функция создания ajax объекта
function createXMLHttp()
	{
	if(typeof XMLHttpRequest != "undefined") { // для браузеров аля Mozilla
		return new XMLHttpRequest(); }
	else if(window.ActiveXObject)
		{ // для Internet Explorer (all versions)
		var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0",
                   "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp",
                   "Microsoft.XMLHttp"
                   ];
	for (var i = 0; i < aVersions.length; i++)
		{
		try { //
			var oXmlHttp = new ActiveXObject(aVersions[i]);
			return oXmlHttp;
			} catch (oError) {
			}
		}
		throw new Error("Невозможно создать объект XMLHttp.");
		}
	}


