function BackRequest(request) {
    var http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                http_request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (e) {}
        }
    }

    if (!http_request) {
        return false;
    }

    http_request.open('POST', '/include/back_request.php', true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(request);
}

function BackRequest_onclick(iCase) {
    var cookieUserFrom = GetCookie('user_from');
    var sUserFrom = (cookieUserFrom != null) ? encodeURIComponent(cookieUserFrom) : '';
    BackRequest('case=' + iCase + '&user_from=' + sUserFrom);
}

function GetCookie(sName) {
	var aCookie = document.cookie.split('; ');
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
  return null;
}

function ElementOnLoad() {
	var cookieUserFrom = GetCookie('user_from');
	if (cookieUserFrom == null) {
		document.cookie = 'user_from=' + escape(document.referrer) + '; path=/';
	}
}

var txt = ''

var postid = ''

function copyPID(pid) {
   postid = pid
}


function copyQ(nick) {
	txt = ''
	if (document.getSelection) {
		txt = document.getSelection()
	} else
	if (document.selection) {
		txt = document.selection.createRange().text;
	}
	if (txt!='')
		txt = '[quote=' + nick + ']' + txt + '[/quote]\n'
}

function insertAtCaret (textObj, textFieldValue) {
	if (document.all) {
		if (textObj.createTextRange && textObj.caretPos && !window.opera) {
			var caretPos = textObj.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?textFieldValue + ' ' : textFieldValue;
		} else {
			textObj.value += textFieldValue;
		}
	} else {
		if (textObj.selectionStart) {
			var rangeStart = textObj.selectionStart;
			var rangeEnd = textObj.selectionEnd;
			var tempStr1 = textObj.value.substring(0, rangeStart);
			var tempStr2 = textObj.value.substring(rangeEnd, textObj.value.length);
			textObj.value = tempStr1 + textFieldValue + tempStr2;
			textObj.selectionStart = textObj.selectionEnd = rangeStart + textFieldValue.length;
		} else {
			textObj.value += textFieldValue;
		}
	}
}

function pasteQ() {
	if (txt!='' && document.forms['post']['req_message'])
		insertAtCaret(document.forms['post']['req_message'], txt)
	else
        if (postid != '')
    	    xajax_quote(postid)
	txt='';postid=''
}

function pasteN(text) {
	if (text != '' && document.forms['post']['req_message'])
	insertAtCaret(document.forms['post']['req_message'], "[b]" + text + "[/b]\n");
}

function openWin(file, title, params)
	{
	w = window.open(file, title, params);
	}



function showimg(u,wd,hg)
                                        {
                                                s = window.open('','Pic','toolbar=no,location=no,directoties=no,status=no,scrollbars=no,menubar=no,resizable=yes,top=20, left=20,width='+(wd+16)+',height='+(hg+16));
                                                s.document.open();
                                                s.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>photo</title></head><body bgcolor=#ffffff onload="window.self.focus();return true;" style="margin: 0px;"><table cellspacing=0 cellpadding=5 border=0 style="height: 100%; width: 100%;"><tr><td align=center><a href=javascript:window.close()><img src="' + u + '" border="0" width="' + wd + '" height="' + hg + '" alt="close"></a></td></tr></table></body></html>');
                                                s.document.close();
                                                s.focus();
                                        }
