

function doneComplaint() {
if (request.readyState == 4){
//alert("OK");
}}

function sendComplaint(uri) {
createRequest();
//alert(uri);
request.open("GET", uri, true);
//request.onreadystatechange = doneComplaint;
request.send(null);
}	
	
	

function createComplaint(again) 
{
var sc=document.getElementById("shop-content");
var c=document.createElement("div");c.id="complaint";
var p=document.createElement("p");
p.onclick=function(){createForm(c,p,sc);};
c.appendChild(p);sc.appendChild(c);
if(again)
{p.innerHTML="<span>Спасибо за Ваше участие<\/span> <span>С Вашей помощью ошибок станет меньше<\/span> <b>Еще ошибки?<\/b>"} else
{p.innerHTML="<span>Неверный телефон?<\/span> <span>Неправильный адрес?<\/span> <span>Ошибки и неточности?<\/span> <b>Сообщите нам<\/b>"}
}

function createForm(c,p,sc) 
{
var i=document.createElement("textarea");i.id="message";i.name="message";i.style.overflowY="hidden";
var s=document.createElement("a");s.appendChild(document.createTextNode("сообщить"));s.id="submit";s.href="#";
var r=document.createElement("a");r.appendChild(document.createTextNode("отмена"));r.id="cancel";r.href="complaint-cancel";
var l=document.createElement("div");l.appendChild(document.createTextNode("Какие есть ошибки или неточности:"));
var f=document.createElement("form");
var shopname=document.getElementById("shop-content").getElementsByTagName("h1")[0].getElementsByTagName("span")[1].childNodes[0].nodeValue;
if(!shopid) var shopid=location.href.split("shop/")[1];
s.onclick=function(){
sendComplaint('/cgi-bin/shop.cgi?act=send_complaint&shop_id='+shopid+'&body='+i.value)
sc.removeChild(c);
createComplaint("again");
return false};
r.onclick=function(){sc.removeChild(c);createComplaint();return false};
l.appendChild(i);
f.appendChild(l);
f.appendChild(s);
f.appendChild(r);
c.removeChild(p);
c.appendChild(f);
}


var initComplaint=new domFunction(function()
{
createComplaint();
});



