function limitTextEd(limitField, limitCount, limitNum) {
	if (document.getElementById(limitField).value.length > limitNum) {
		document.getElementById(limitField).value = document.getElementById(limitField).value.substring(0, limitNum);
	} else {
		document.getElementById(limitCount).value = limitNum - document.getElementById(limitField).value.length;
	}
}


function submitenter(myfield,e,burl)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   send(burl);
   return false;
   }
else
   return true;
}




/* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function ErrorField( message, id ) {

	alert( message ) ;
	document.getElementById(id).focus();
	return false;

}

function addbasket(burl, tid) {
  var url = burl + "index.php/main/addbasket/" + tid;

  // Открыть соединение с сервером
  xmlHttp.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = refbasket;

  // SПередать запрос
  xmlHttp.send(null);
}

function refbasket() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (document.getElementById("basket").innerHTML == response) {
    	alert('такой товар уже есть на примерке');
    } else {
    document.getElementById("basket").innerHTML = response;
    alert('товар добавлен на примерку');
    	
    	}
  }
    }
function login(burl) {
  
    var login = document.getElementById("login").value;
    var pass = document.getElementById("pass").value;
    
    if( login == '' ) { return ErrorField( 'Укажите логин', login ); }
    if( pass == '' ) { return ErrorField( 'Укажите пароль', pass ); }
  
    var url = burl + "index.php/main/login";
    var params = 'login=' + encodeURIComponent(login) + '&pass=' + encodeURIComponent(pass);
    
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}

function net() {
	
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("net").innerHTML = response;
    
    	
  }
    }
function chatin() {
	
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("chat").innerHTML = response;
    
    	
  }
    }
function rate() {
	
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("rating").innerHTML = response;
    
    	
  }
    }
function showbuy() {
	
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("butics").style.display = "block";
    
    	
  }
    }
    
function reg(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/registration";
    
    
    
  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}

function remind(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/remind";
    
    
    
  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}

function remindsend(burl) {
  
    var mail = document.getElementById("mail").value;
    
    
    if( mail == '' ) { return ErrorField( 'Укажите почту', mail ); }
    
  
    var url = burl + "index.php/main/remindsend";
    var params = 'mail=' + encodeURIComponent(mail);
    
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}



function gomain(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/netmain";
    
    
    
  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}
function gonet(burl) {
document.getElementById("chat").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
    var url = burl + "index.php/main/netnet";
    //var params = 'user=' + encodeURIComponent(uid);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}
function exit(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/logout";
    
    
    
  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}

function addfriend(burl) {
  
    var login = document.getElementById("login").value;
    
    if( login == '' ) { return ErrorField( 'Укажите логин', login ); }
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';    
  
    var url = burl + "index.php/main/addfriend";
    var params = 'login=' + encodeURIComponent(login);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}
function invite(burl) {
  
    var mail = document.getElementById("mail").value;
    
    if( mail == '' ) { return ErrorField( 'Укажите адрес электронной почты', mail ); }
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';    
  
    var url = burl + "index.php/main/invite";
    var params = 'mail=' + encodeURIComponent(mail);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}

function deletefr(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/delfriend";

  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}

function deleteno(burl) {
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
  
    var url = burl + "index.php/main/delfriendno";

  // Открыть соединение с сервером
    xmlHttp.open("GET", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
//    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(null);
}

function allow(burl, uid) {
  
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
    var url = burl + "index.php/main/allow";
    var params = 'user=' + encodeURIComponent(uid);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}
function disallow(burl, uid) {
 document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>'; 
  
    var url = burl + "index.php/main/disallow";
    var params = 'user=' + encodeURIComponent(uid);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}

function add() {
	document.getElementById('profile').style.display = "none";
	document.getElementById('propic').className = "offpic";
	document.getElementById('invite').style.display = "none";
	document.getElementById('invpic').className = "offpic";
	document.getElementById('delete').style.display = "none";
	document.getElementById('delpic').className = "offpic";
	
	if (document.getElementById('add').style.display=="none") {document.getElementById('add').style.display = "block"; document.getElementById('addpic').className = "onpic";} else {document.getElementById('add').style.display = "none";document.getElementById('addpic').className = "offpic";};
	}
function profile() {
	document.getElementById('add').style.display = "none";
	document.getElementById('addpic').className = "offpic";
	document.getElementById('invite').style.display = "none";
	document.getElementById('invpic').className = "offpic";
	document.getElementById('delete').style.display = "none";
	document.getElementById('delpic').className = "offpic";

	if (document.getElementById('profile').style.display=="none") {document.getElementById('profile').style.display = "block"; document.getElementById('propic').className = "onpic";} else {document.getElementById('profile').style.display = "none";document.getElementById('propic').className = "offpic";};
	}	
function inv() {
	document.getElementById('profile').style.display = "none";
	document.getElementById('propic').className = "offpic";
	document.getElementById('add').style.display = "none";
	document.getElementById('addpic').className = "offpic";
	document.getElementById('delete').style.display = "none";
	document.getElementById('delpic').className = "offpic";

	if (document.getElementById('invite').style.display=="none") {document.getElementById('invite').style.display = "block"; document.getElementById('invpic').className = "onpic";} else {document.getElementById('invite').style.display = "none";document.getElementById('invpic').className = "offpic";};
	}
function del() {
	document.getElementById('profile').style.display = "none";
	document.getElementById('propic').className = "offpic";
	document.getElementById('invite').style.display = "none";
	document.getElementById('invpic').className = "offpic";
	document.getElementById('add').style.display = "none";
	document.getElementById('addpic').className = "offpic";

	if (document.getElementById('delete').style.display=="none") {document.getElementById('delete').style.display = "block"; document.getElementById('delpic').className = "onpic";} else {document.getElementById('delete').style.display = "none";document.getElementById('delpic').className = "offpic";};
	}
	
function changepass(burl) {
  
    var oldpass = document.getElementById("oldpass").value;
    var newpass = document.getElementById("newpass").value;
    
document.getElementById("net").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';    
  
    var url = burl + "index.php/main/changepass";
    var params = 'oldpass=' + encodeURIComponent(oldpass) + '&newpass=' + encodeURIComponent(newpass);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}

function chat(burl, uid) {
  
document.getElementById("chat").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
    var url = burl + "index.php/main/chat";
    var params = 'user=' + encodeURIComponent(uid);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}
function send(burl) {
  	var mess = document.getElementById("mess").value;
document.getElementById("chat").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
    var url = burl + "index.php/main/send";
    var params = 'mess=' + mess;
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = net;

  // SПередать запрос
  xmlHttp.send(params);
}

function sendp(burl) {
  	var mess = encodeURIComponent(document.location.href);
  	document.getElementById("chat").innerHTML = '<p class="load"><img src="' + burl + 'pic/load.gif"></p>';  
		var url = burl + "index.php/main/send";
		var params = 'pmess=' + mess;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = net;
		xmlHttp.send(params);
}

	
	function plus(burl, tid) {
  var url = burl + "index.php/main/plus/" + tid;

  // Открыть соединение с сервером
  xmlHttp.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = rate;

  // SПередать запрос
  xmlHttp.send(null);
}
	function minus(burl, tid) {
  var url = burl + "index.php/main/minus/" + tid;

  // Открыть соединение с сервером
  xmlHttp.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = rate;

  // SПередать запрос
  xmlHttp.send(null);
}
	function buy(burl, tid) {
  var url = burl + "index.php/main/buy/" + tid;

  // Открыть соединение с сервером
  xmlHttp.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = showbuy;

  // SПередать запрос
  xmlHttp.send(null);
}
function closechat(burl) {
  

    var url = burl + "index.php/main/closechat";
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = net;
  xmlHttp.send(null);
}

function getSelectedText(burl) 
{ 
    var selText = ""; 
    if (document.getSelection)// Mozilla 
    { 
        selText = document.getSelection(); 
    } 
    else if (document.selection) // IE 
    { 
        selText = document.selection.createRange().text; 
    } 
    else if (window.getSelection) // Safari 
    { 
        selText = window.getSelection(); 
    } 
    if(selText) { 
        senderrortext(burl, selText);
    } 
}

function senderrortext(burl, seltext) {
  	
    var url = burl + "index.php/main/senderrortext";
    var params = 'text=' + seltext + '&url=' + encodeURIComponent(document.location.href);
    
    
  // Открыть соединение с сервером
    xmlHttp.open("POST", url, true);
    //xmlhttp.setRequestHeader("Content-Type", "application/x-www-form");
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form");
  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = alert('Спасибо Вам, мы постараемся как можно быстрее отреагировать на Ваше замечание.');

  // SПередать запрос
  xmlHttp.send(params);
}
