// Набор служебныx функций
var ie = document.all ? true : false;
var ns = document.layers ? true : false;
var width1 = ns ? 4 : 8;

String.prototype.trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

function doFind(par){
	if(par.EMAIL.value==""){
		alert("Введите E-mail!");
		par.EMAIL.focus();
		return false;
	}
	if(par.PASSWORD.value.length==0){
		alert("Вы не указали пароль!");
		par.PASSWORD.focus();
		return false;
	}
	var e=false; for (var i=0; i<par.length; i++) if (par[i].name=="ok") e=true;
	if(e){par.ok.disabled=true;}
	par.ACT.value=1;
	par.fill.disabled=true;
	par.canc.disabled=true;
	par.submit();
}

function CheckProc(par){
	if (par.FIRM.value.length==0){alert("Укажите название фирмы!");par.FIRM.focus();return false;}
	if (par.EMAIL.value.length==0){alert("Укажите адрес e-mail!");par.EMAIL.focus();return false;}
	if ((par.EMAIL.value.indexOf("@")==-1)||(par.EMAIL.value.indexOf(".")==-1)||(par.EMAIL.value.length<6)){
		alert ("Вы ввели неправильный адрес e-mail!");par.EMAIL.focus();return false;}
	return true;
}

function CheckInput(par){
	if (!CheckProc(par)) return false;
	if((par.FIZ.checked==false)&&(par.ADDRESS.value.length==0)){alert("Необходимо указать почтовый адрес для отправки документов!");par.ADDRESS.focus();return false;}
	if(par.PASSWORD.value.length==0){alert("Вы не указали пароль!");par.PASSWORD.focus();return false;}
	var e=false; for (var i=0; i<par.length; i++) if (par[i].name=="ok") e=true;
	if(!e){alert("Корзина пуста! ");return false;}else{par.ok.disabled=true;}
	par.ACT.value=2;
	par.fill.disabled=true;
	par.canc.disabled=true;
	par.submit();
}

function CheckInputFree(par){
	if (!CheckProc(par)) return false;
	if (par.ADDRESS.value.length==0){alert("Укажите адрес!");par.ADDRESS.focus();return false;}
	if (par.COMMENT.value.length==0){alert("Не указано содержание заказа!");par.COMMENT.focus();return false;}
	par.submit();
}

function CheckMess(par){
	with(par.MESSAGE){
		var tr=par.MESSAGE.value.trim(); 
		if(tr.length==0){alert("Нет текста сообщения!");par.MESSAGE.value="";par.MESSAGE.focus();return false;}
		par.submit();
	}
}


function OpenWind(sURL,sWN,L,T,W,H){
	nwin=window.open(sURL,sWN,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+W+',height='+H+',top='+T+',left='+L);
	nwin.focus();
}

function OpenSharedWind(sURL){
	OpenWind(sURL,"SharedWind",0,0,620,document.body.clientHeight);
}

function OpenSharedWindEx(sURL){
	OpenWind(sURL,"SharedWindEx",0,0,document.body.clientWidth-50,document.body.clientHeight);
}

function selectOKS(){
	var W=550,H=document.body.clientHeight,L=screen.width-W-15;
	OpenWind("/oks.asp?q=1","okswin",L,0,W,H);
}
function doSelectOKS(x){
	with(window){opener.document.seek1.soks.value=x; opener.focus(); close();}
}
function selectGroup(){
	var W=550,H=document.body.clientHeight,L=screen.width-W-15;
	OpenWind("/group.asp?q=1","grpwin",L,0,W,H);
}
function doSelectGroup(x){
	with(window){opener.document.seek1.sgr.value=x; opener.focus(); close();}
}



function OpenCart(){
	var W=620,H=document.body.clientHeight;
	OpenWind("/cart.asp","CartWind",0,0,W,H);
}

function AddItem(ct,ci) {
	var H=document.body.clientHeight;
	OpenWind("/cart.asp?ct="+ct+"&ci="+ci+"&rand='"+Math.random()+"'","CartWind",0,0,620,H);
}

function lostpassw(){
	var L=screen.width-610;H=document.body.clientHeight/1.2;
	OpenWind("/user/?q=1&cmd=lost","upass",L,0,600,H);
}
function changepassw(){
	var L=screen.width-610;H=document.body.clientHeight/1.2;
	OpenWind("/user/?q=1&cmd=pass","upass",L,0,600,H);
}

function OpenSamplePage(np){
	OpenWind("/sample/gp"+np+".gif","smplwnd",0,0,document.body.clientWidth-50,document.body.clientHeight);	
}


function checkboxproc(par,onoff){
	for (var i=0; i<par.length; i++) if (par[i].type=="checkbox"){par[i].checked = onoff;}
}
function checkall(par){
	checkboxproc(par,true);
}
function uncheckall(par){
	checkboxproc(par,false);
}

function flash(s) {
with(document.all[s]){
	if (className!='warn') 
		className='warn'
	else 
		className='warn2';
}
eval("setTimeout(\"flash('"+s+"')\",400)");
}


function ShowBack(){
if(history.length>0)
document.write("<a href='javascript:history.back();'>&laquo;&nbsp;назад&nbsp;</a>");
}

function ShowBackBut(){
if(history.length>0)
document.write("<input class=b1 type=button value='Назад' onclick='history.back();'>");
}








function SendZakaz(){
  if (!confirm("Отправить Ваш заказ?")) return false;
  location.href("/supply_send.asp?rand='"+Math.random()+"'&z="+sCookie);
}

function _findCookie(name){
var aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++) {
    var aCrumb = aCookie[i].split("=");
    if (name == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  return "";
}

function findCookie(sName){
  var i=nstart=nend=0;
  var cookiestr=document.cookie;
  while (i <= cookiestr.length){
    nstart=i; nend=i+sName.length;
    if (cookiestr.substring(nstart,nend)==sName){
	  nstart=nend+1;
      nend=cookiestr.indexOf(";",nstart);
      if (nend<=nstart) nend=cookiestr.length;
      return cookiestr.substring(nstart,nend);
      break;
    }
    i++;
  }
  return "";
}
function showcookie(){
  alert(unescape(document.cookie))
}
function removeCookie(szName){
var szvalue = findCookie(szName);
var dtend=new Date();
  dtend.setTime(dtend.getTime()-1);
  document.cookie = szName + "=" + szvalue+"; expires="+dtend.toGMTString();
}



function CheckPass(){
with (document.chngp){
 if (EMAIL.value.trim()==""){alert("Не указан E-Mail!");EMAIL.focus();return;}
 if ((EMAIL.value.indexOf("@")==-1)||(EMAIL.value.indexOf(".")==-1)||(EMAIL.value.length<5))
    {alert("Указан неправильный адрес E-Mail!");EMAIL.focus();return;}
 if (OLDPASS.value.trim()==""){alert("Не указан старый пароль!");OLDPASS.focus();return;}
 if (NEWPASS.value.trim()==""){alert("Не указан новый пароль!");NEWPASS.focus();return;}
 if (NEWPASS2.value.trim()==""){alert("Повторите ввод нового пароля!");NEWPASS2.focus();return;}
 if (NEWPASS.value.trim()!=NEWPASS2.value.trim()){alert("Введены разные пароли!");NEWPASS2.focus();return;}
 if (NEWPASS.value.trim()==OLDPASS.value.trim()){alert("Вообще-то, новый пароль должен отличаться от старого!");NEWPASS.focus();return;}
 submit();
}
}

