// *********************************************************************************************
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;
	}


// 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);
}

