// JavaScript Document
/* <![CDATA[ */

var win1;
var win2;
function busket(bar) {
 win1 = window.open("/busket.phtml?add=1&barcode="+bar, "Корзина", "toolbar=0,width=600,height=600,scrollbars=1");
 win1.focus();
}

function expensive(bar) {
 win1 = window.open("/expensive.phtml?bc="+bar, "Дорого?", "toolbar=0,width=500,height=240,scrollbars=1");
 win1.focus();
}


function jpeg_view(current, bar) {
 win1 = window.open("/jpeg.phtml?current="+current+"&barcode="+bar, "Отрывок", "toolbar=0,width=600,height=600,scrollbars=1,resizable=yes");
 win1.focus();
}

function fig_view(current, bar) {
 win1 = window.open("/gif.phtml?current="+current+"&barcode="+bar, "Отрывок", "toolbar=0,width=600,height=600,scrollbars=1,resizable=yes");
 win1.focus();
}

function fig_view1(current, bar) {
 win1 = window.open("/gif1.phtml?current="+current+"&barcode="+bar, "Содержание", "toolbar=0,width=600,height=600,scrollbars=1,resizable=yes");
 win1.focus();
}


function preorder(barcode) {
 win1 = window.open("/preorder.phtml?add=1&barcode="+barcode, "Корзина", "toolbar=0,width=600,height=600,scrollbars=1");
 win1.focus();
}

function showNote(page) {
 win1 = window.open(page, 'Подсказка', 'toolbar=0,width=300,height=170,scrollbars=0');
 win1.focus();
}


function inMain(lctn) {
 try 
 {
  if (window.opener) {
   if (lctn == 'refresh') {
    window.opener.location.reload();
   }
   else {
    window.opener.location=lctn; 
    window.close();
   }
  }	
 } 
 catch(e)
 { 
  alert('Возможно, вы закрыли основное окно сайта');
 }
}


function fulwin(path) {
win1.close();
win = window.open("path", "Корзина");
win.focus();
}




function busket_view(order) {
 win1 = window.open("/busket.phtml?view=1&order="+order, "Корзина", "toolbar=0,width=600,height=600,scrollbars=1");
 win1.focus();
}


function busket_view_old(order) {
 win1 = window.open("/busket.phtml?viewold=1&order="+order, "Корзина", "toolbar=0,width=600,height=600,scrollbars=1");
 win1.focus();
}

function busket_finish_old(order) {
 win1 = window.open("/busket.phtml?buy=1&order="+order, "Корзина", "toolbar=0,width=600,height=600,scrollbars=1");
 win1.focus();
}


function map_pr(im) {
var str_m="/pred_map/"+im;

window.open(str_m, "Карта", "toolbar=0,width=400,height=400");

}

var xmlHttp = createXmlHttpRequestObject(); 
// stores the reference to the XMLHttpRequest object

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      
    }
    catch (e) 
    {
    
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    
    }
    catch (e) 
    {
      xmlHttp = false;
    
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Ошибка совместимости JavaScript. Возможно, некоторые функции навигации будут для вас недоступны");
  else 
    return xmlHttp;
}
// make asynchronous HTTP request using the XMLHttpRequest object 
function process(tmp)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // retrieve the name typed by the user on the form
        if(tmp>"001000") {
        
      
         xmlHttp.open("GET", "/catalogue.phtml?for_sort="+tmp, true);  
        
        
        }
        if(tmp==4){

    	fio = encodeURIComponent(document.getElementById("fio").value);
    	emls = encodeURIComponent(document.getElementById("emls").value);
    	last_oid = encodeURIComponent(document.getElementById("last_oid").value);
  	xmlHttp.open("GET", "/quickstart.php?fio=" + fio+"&emls="+emls+"&last_oid="+last_oid, true);  
    	}
    
    
    if(tmp==1){
    	login = encodeURIComponent(document.getElementById("oldlogin").value);
    	passwd = encodeURIComponent(document.getElementById("oldpasswd").value);
    	 xmlHttp.open("GET", "/quickstart.php?login=" + login+"&passwd="+passwd, true);  
    	}
if(tmp==2){

    	email = encodeURIComponent(document.getElementById('email').value);
    	str = "/quickstart.php?email=" + email;
    	xmlHttp.open("GET", str, true);  
    	}    	
    	
    	
    if(tmp==0){
    name = encodeURIComponent(document.getElementById("login").value);
    // execute the quickstart.php page from the server

    xmlHttp.open("GET", "/quickstart.php?name=" + name, true);  
    }
    // define the method to handle server responses

    xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
//    alert(document.getElementById("ok").value);
  }
//  else
    // if the connection is busy, try again after one second  
//    setTimeout('process()', 1000);
}



var gFS;


function showCat() 
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200) 
    {
      answer = xmlHttp.responseText;
      document.getElementById(gFS).innerHTML = answer;
      document.getElementById(gFS).style.display = "block";
    } 
    else 
    {
      alert("Попробуйте перезагрузить страницу. Ошибка связи с сервером");
    }
  }
}

function getCat(forSort)
{
  pImage = 'http://www.piter.com/i/p.gif';
  mImage = 'http://www.piter.com/i/m.gif';
  if (document.getElementById('i'+forSort)) {
   if (document.getElementById('i'+forSort).src == pImage) document.getElementById('i'+forSort).src = mImage;
   else document.getElementById('i'+forSort).src = pImage;
  }
  if (document.getElementById(forSort).style.display == "block") { 
	 document.getElementById(forSort).style.display = "none";
  } else {	
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
    gFS = forSort;
    xmlHttp.open("GET", "/catalogue.phtml?getforsort="+getforsort+"&ajx_for_sort="+forSort, true);  
    xmlHttp.onreadystatechange = showCat;
    xmlHttp.send(null);
   }
  } 
}



function handleServerResponse() 
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200) 
    {
      helloMessage = xmlHttp.responseText; 
//alert(helloMessage);
ibname=helloMessage.split("|");
//alert(ibname[0]);
//if(document.getElementById(ibname[0])) alert("1");
     if(document.getElementById(ibname[0])) document.getElementById(ibname[0]).innerHTML = 
                                             ibname[1];


      
//	if(document.getElementById("ok")) alert("ok!") else alert("no!");
      // restart sequence
//      setTimeout('process()', 1000);
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function validate() {
	return true;
	if(document.getElementById('p1').value!=document.getElementById('p2').value) {
		alert("Пароли не совпадают");
		document.getElementById('p1').focus();
		return false;
	}
		 
	if(document.getElementById('p1').value.length<4) {
		alert("Пароль должен быть больше 6 символов");
		document.getElementById('p1').focus();
		return false;
	}
	
	if(document.getElementById('login').value.length<3) {
		alert("Логин должен быть больше 3 символов");
		return false;
	}

	if(document.getElementById('last').value.length<2) {
		alert("Введите вашу фамилию!");
		return false;
	}
	if(document.getElementById('name').value.length<2) {
		alert("Введите ваше имя!");
		return false;
	}

	if(document.getElementById('mail').value.length<6 || document.getElementById('mail').value.indexOf('@')==-1) 
        {
		alert("проверьте ваш e-mail адрес");
		return false;
	}
	
	if(document.getElementById('regions_id').value==0 ) 
        {
		alert("Не указан регион проживания");
		return false;
	}
	return true;	

}



function view_rubr(tmp)
{
 document.getElementById(tmp).style.display = "block";
}


function Toggle(tmp)
{
 if (document.getElementById(tmp).style.display=="none") document.getElementById(tmp).style.display = "block";
 else document.getElementById(tmp).style.display = "none"; 
}



function createWin(ids,id)
{
 if (ids==2) window.open("/chapt.phtml?id="+id+"&param=1","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==1) window.open("/chapt.phtml?id="+id+"&param=2","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==3) window.open("/pred.phtml?id="+id,"","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==4) window.open("/cont.phtml?id="+id+"&gr_p=1","","width=630,height=700,status=0,scrollbars=1,toolbar=0")
 if (ids==5) window.open("/chapt.phtml?id="+id+"&gr_p=7","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==6) window.open("/contents/"+id+"/cont.pdf","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==7) window.open("/contents/"+id+"/chapt.pdf","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
 if (ids==11)window.open("/contents/978546900989/rus_h.htm","","width=630,height=580,status=0,scrollbars=1,toolbar=0")
}



/* ]]> */
